# Scale x axes in ListContourPlot

I have list of data which I visualize by using ListContourPlot.

data = Table[RandomReal[i]*RandomReal[j], {i, 5}, {j, 6}];

ListContourPlot[data, AspectRatio -> 1/10, ImageSize -> 700]


Each column of data correspondes to a segment which has a certain length. For example:

segments = {{0, 5}, {5, 12}, {12, 27}, {27, 32}, {32, 35}, {35, 40}}


Now I would like to rescale the x axes so that the columns have the right length in the plot. If possible also the caption of the x axes should match.

-Frink

-

You can probably solve the problem by giving explicit x, y, z coordinates for the data. In your case, I would first define the x position based on your segments:

pos = Mean /@ segments;


Then we can create a dataset that consists of 5 rows and 6 columns, but where the position of each column is defined by the above pos:

newdata = Join @@ Table[{pos[[i]], j, RandomReal[i]}, {j, 5}, {i, 6}];


The ListContourPlot with the x-axis specified by using FrameTicks:

ListContourPlot[newdata, AspectRatio -> 1/10, ImageSize -> 700,
FrameTicks -> {{Automatic, None}, {Union @@ segments, None}}]


Update

To add some strings that contain information about the single segments you might do this:

ListContourPlot[newdata, AspectRatio -> 1/10, ImageSize -> 700,
FrameTicks -> {{Automatic,
None}, {Join @@ {Transpose[{Union @@ segments,
Union @@ segments}],
Transpose[{pos, {"Seg.1", "Seg.2", "Seg.3", "Seg.4", "Seg.5",
"Seg.6"}}]}, None}}]


At this point, I've noticed that it would be better to add some data points at x values of 0 and 40 to define the exact range of your plot. These additional data points have a z-value equal to 0.

newdata2 = Join[newdata, Transpose[{Table[0, {5}], Range[5], Table[0, {5}]}],
Transpose[{Table[40, {5}], Range[5], Table[0, {5}]}]];

ListContourPlot[newdata2, AspectRatio -> 1/10, ImageSize -> 700,
FrameTicks -> {{Automatic,
None}, {Join @@ {Transpose[{Union @@ segments,
Union @@ segments}],
Transpose[{pos, {"Seg.1", "Seg.2", "Seg.3", "Seg.4", "Seg.5",
"Seg.6"}}]}, None}}]


-
I was about to post an answer but I like yours better. Do you mind if I make a few changes? – Mr.Wizard Oct 15 '12 at 9:15
@Mr.Wizard Go ahead. – VLC Oct 15 '12 at 9:16

Building on VLC's answer, to convert existing data you might do something like this:

SeedRandom[14];
data = Table[RandomReal[i]*RandomReal[j], {i, 5}, {j, 6}];

ListContourPlot[data, AspectRatio -> 1/10, ImageSize -> 700]


segments = {{0, 5}, {5, 12}, {12, 27}, {27, 32}, {32, 35}, {35, 40}};

pos = Mean /@ segments;

data2 = Join @@ MapIndexed[{pos[[#2[[2]]]], #2[[1]], #} &, data, {2}];

ListContourPlot[data2, AspectRatio -> 1/10, ImageSize -> 700,
FrameTicks -> {{Automatic, None}, {Union @@ segments, None}}]


-
big thank you @VLC and Mr.Wizard. It works really perfect. There is one thing in addition which I would like to do with the plot. I have a list of Strings which contains some facts about each of the segments. For example: '{"Seg.1","Seg.2","Seg.3","Seg.4","Seg.5","Seg.6"}'. Is it possible to write this information at the right posizion under the plot (or directly into the plot)?. -Frink – RMMA Oct 15 '12 at 13:37
@Frink See my update. – VLC Oct 15 '12 at 14:25
@VLC thx for your updates, looks nice and works fine! – RMMA Oct 16 '12 at 6:14
one further question: Is it possible the take the values constant for each segment? -Frink – RMMA Oct 16 '12 at 7:36
@Frink unless your last comment is addressing me you forgot @VLC – Mr.Wizard Oct 16 '12 at 8:22