Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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:

fakeData=Table[BinCounts[RandomVariate[NormalDistribution[71,1.5],1000],{0,85,0.5}],{j,1,100}];

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:

xScaleInitially=Range[Length[fakeData[[1,All]]]];

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

xScaleTransformed=1⁄((10+Sqrt[xScaleInitially]));

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

fakeDataTransformed=Table[Transpose[{xScaleTransformed,fakeData[[j]]}],{j,1,100}];

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!

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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], 
    precision}]]

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

MatrixPlot[newdata]

transformed MatrixPlot[]

share|improve this answer
    
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? –  partial81 Oct 5 '12 at 15:07
    
@partial81 Do you mean that my example doesn't run for you or it doesn't run with your larger matrix? –  VLC Oct 5 '12 at 15:15
    
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. –  partial81 Oct 5 '12 at 15:31
    
@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? –  VLC Oct 5 '12 at 15:38
    
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!! –  partial81 Oct 8 '12 at 7:00
show 1 more comment

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[]

Question!

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?

BR

share|improve this answer
    
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). –  partial81 Oct 5 '12 at 15:13
    
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. –  PlatoManiac Oct 5 '12 at 15:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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