I have to transform in a nonlinear way the x-scale of some data for a MatrixPlot (or ReliefImage or ListDensityPlot etc.).

Let me give an example to explain what I try to do.

I have following fake data:


Which I can plot easily with e.g. MatrixPlot[fakeData], which gives Output of MatrixPlot for fakeData

Or I can plot just one line of the fake data with ListPlot[fakeData[[3]]], which gives Output of ListPlot for fakeData

But the xscale of the data is not correct and should be transformed. The initial scale is linear:


and the transformed scale should be something like, e.g.:


Then I can try to transform all my data with e.g.:


If I use ListPlot[fakeDataTransformed[[3]]], I get for these data the result I want to have: Output of ListPlot for transformed fakeData

But I cannot manage to use MatrixPlot or ReliefImage on these transformed data to get a picture similar to the first one above.

Could somebody of you tell me how I can transform my data correctly, so that I still can have plots as with MatrixPlot or ReliefImage etc.? I would be very happy about every hint and help!


2 Answers 2


How about interpolating your fakeDataTransformed, to obtain regularly spaced data points?

func[line_, precision_] := Module[{f},
    f = Interpolation[fakeDataTransformed[[line]]];
    Table[f[x], {x, Min[xScaleTransformed], Max[xScaleTransformed], 

newdata = Table[func[i, .0002], {i, Length[fakeDataTransformed]}];


transformed MatrixPlot[]

  • $\begingroup$ Seems to be a good approach, but your code does not run for me out of some unknown reasons. My real data are in a 450x1600 Matrix. Do you think that your code (if it runs) will work for such a big Matrix? $\endgroup$
    – partial81
    Commented Oct 5, 2012 at 15:07
  • $\begingroup$ @partial81 Do you mean that my example doesn't run for you or it doesn't run with your larger matrix? $\endgroup$
    – VLC
    Commented Oct 5, 2012 at 15:15
  • $\begingroup$ Unfortunately, it does not run for me, and somehow I cannot find the error. So, before I spend more time to get it running, I just wanted to know if it will work then with my larger matrix. $\endgroup$
    – partial81
    Commented Oct 5, 2012 at 15:31
  • $\begingroup$ @partial81 Hm, I just copied all the bits from your question and those from my answer in a fresh kernel and it runs. With larger matrices it will just take more time to compute. Do you get any meaningful error at least? Maybe you didn't specify fakeDataTransformed or xScaleTransformed? $\endgroup$
    – VLC
    Commented Oct 5, 2012 at 15:38
  • $\begingroup$ Sorry for the late reply. I did not have access to a computer with mathematica this weekend. When I copied my code from this webpage, the “/” in xScaleTransformed was not correctly copied. After correcting this, your code runs really well, even for my bigger matrixes (after reducing the precision)! Thanks a lot for solving my problem!! $\endgroup$
    – partial81
    Commented Oct 8, 2012 at 7:00

Check this and modify ticks according the way you want:

MatrixPlot[Transpose@Reverse@Transpose@fakeData, AspectRatio -> 3/5,
DataReversed -> {True, False}, DataRange -> {{0,2}, All}]

transformed MatrixPlot[]


I tried to manipulate the FrameTicks but could not get the wanted result.

chosen = Take[xScaleTransformed = 1/((10 + Sqrt[xScaleInitially])) // N, {1, -1,20}]; 
xticks = Transpose[{Range@Length@chosen, chosen}];
yticks = Transpose[{Range@10,Take[Range[First@Dimensions@fakeData], {1, -1, 10}]}];
MatrixPlot[Transpose@Reverse@Transpose@fakeData, AspectRatio -> 3/5, 
DataReversed -> {True, False}, FrameTicks -> {yticks, xticks}]

FrameTicks scaling attempt

Can anybody shed some light at this issue?


  • $\begingroup$ Thanks for the answer. But do you think that using Reverse is really a good idea? Just in my example it seems that it is enough to reverse the data. But another transformation could transform the data to other values where reversing will not work. I also see that you try to change the x-scale to a non-linear scale. But as in my example I would prefer to have a normal, linear scale (that is why my transformed data are narrower than before the transformation). $\endgroup$
    – partial81
    Commented Oct 5, 2012 at 15:13
  • $\begingroup$ I guess Reverse will work for any data. It just reorders the data matrix to suit well for Transpose. For the x-scale I just used your specified scaling. You have freedom to choose linear one if you want. $\endgroup$ Commented Oct 5, 2012 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.