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

ListContourPlot

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

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

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

ListContourPlot

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

ListContourPlot

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

ListContourPlot

share|improve this answer
    
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
add comment

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]

Mathematica graphics

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

Mathematica graphics

share|improve this answer
    
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
show 3 more comments

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.