4
$\begingroup$

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

$\endgroup$

2 Answers 2

4
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ I was about to post an answer but I like yours better. Do you mind if I make a few changes? $\endgroup$
    – Mr.Wizard
    Commented Oct 15, 2012 at 9:15
  • $\begingroup$ @Mr.Wizard Go ahead. $\endgroup$
    – VLC
    Commented Oct 15, 2012 at 9:16
0
$\begingroup$

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

$\endgroup$
8
  • $\begingroup$ 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 $\endgroup$
    – RMMA
    Commented Oct 15, 2012 at 13:37
  • $\begingroup$ @Frink See my update. $\endgroup$
    – VLC
    Commented Oct 15, 2012 at 14:25
  • $\begingroup$ @VLC thx for your updates, looks nice and works fine! $\endgroup$
    – RMMA
    Commented Oct 16, 2012 at 6:14
  • $\begingroup$ one further question: Is it possible the take the values constant for each segment? -Frink $\endgroup$
    – RMMA
    Commented Oct 16, 2012 at 7:36
  • $\begingroup$ @Frink unless your last comment is addressing me you forgot @VLC $\endgroup$
    – Mr.Wizard
    Commented Oct 16, 2012 at 8:22

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.