Message Boards Message Boards

0
|
1432 Views
|
5 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Graphics overlay doesn't work properly

Posted 10 months ago

I have two Graphics images, the first generated by Manipulate and the second generated directly that don’t overlap correctly. Changing both primary graphs to Manipulate doesn’t solve the problem. Version that overlays properly (See attached notebook)

  Version that doesn’t overlay properly (see attached notebook)

  The underlying definitions

In[24] = lineLONCUR = Line[{{iloncapture2, 1}, {iloncapture2, 9}}]
In[25] = lineLONGRA = Show[Graphics[lineLONCUR]]
In[26]:= lineTRKCUR = Line[{{0.0, 1.6}, {1.7, 3.2}, {3.4, 4.2}, {5.1, 5.4}, {6.9, 6.2}, {8.6, 6.2}, {103, 6.1}}];
In[27]:= Line[{{0.`, 1.6`}, {1.7`, 3.2`}, {3.4`, 4.2`}, {5.1`, 5.4`}, {6.9`, 6.2`}, {8.6`, 6.2`}, {103, 6.1`}}];
In[28]:= Line[{{0.`, 1.6`}, {1.7`, 3.2`}, {3.4`, 4.2`}, {5.1`, 5.4`}, {6.9`, 6.2`}, {8.6`, 6.2`}, {103, 6.1`}}];
In[29]:= lineTRKGRA = Show[Graphics[{Green, Thick, lineTRKCUR}]]
In[30]:= lineTURCUR = Line[{{8.51, 5.85}, {8.71, 5.85}}];
In[31]:= lineTURGRA = Show[Graphics[{Red, Thick, lineTURCUR}]]

The one that overlays properly

Manipulate[
  wspdLEVshort2 = 
   Table[wspd3d[[klev, jlat, ilon]], {jlat, nlat, 1, -1}, {ilon, 1,  nlon, 1}];
  klevcapture = klev;
  gLEV1 = 
   ListContourPlot[wspdLEVshort2, ContourLabels -> All, AxesLabel -> {Longitude, Latitude}, 
    Contours -> {90, 80, 70, 60, 50, 40} , PlotLabel -> "wspdLEV",  PlotLegends -> Automatic]
  , {{klev, 3}, 1, 5, 1}
  ]
 ]

gLEV1comb = Show[gLEV1, lineLONGRA, lineTRKGRA, lineTURGRA]

The one that doesn’t overlay properly

gLEV2 = ListContourPlot[wlinLEV, ContourLabels -> All, 
  AxesLabel -> {Longitude, Latitude}, 
  Contours -> {90, 80, 70, 60, 50, 40} , PlotLabel -> "wspdLEV", 
  PlotRegion -> {{0.0, 1.0}, {0.0, 1.0}}, PlotLegends -> Automatic]

v2LEV2comb = Show[{lineLONGRA, lineTRKGRA, lineTURGRA, gLEV2}]
Attachments:
POSTED BY: Joel Tenenbaum
5 Replies

It appears to be a problem of PlotRange. When you Show more than one plot, the overlay will use the PlotRange of the first plot. Also, if gLEV2 is last, it will sit on top of the previous lines and make them invisible underneath. Place gLEV2 first in the list:

Show[gLEV2,lineLONGRA, lineTRKGRA, lineTURGRA]

Otherwise, use Epilog within ListContourPlot. By the way, there is no need for Show when only one Graphics is inside: Show[Graphics[lineLONCUR]] is the same as Graphics[lineLONCUR]

POSTED BY: Gianluca Gorni

Thanks for the suggestions. Some background: the difference between gLEV1 and gLEV2 is to get the axis labels to be the meteorologically appropriate values, with fake negative pressures to get the correct vertical display of atmospheric pressure (-150 hPa at top) and Latitude (60N to 40N). The figure is a slice of wind speed through the jet stream.

When I put gLEV2 at the start, i.e. Show[{gLEV2, lineLONGRA, lineTRKGRA, lineTURGRA}] I get a blank display box but otherwise proper x and y axis labels and the color legends.

Which function, ListContourPlot or Show takes the PlotRange parameters? Am I understanding correctly that these should be -350 to -150 (negative pressure in hectoPascals) and -70 to 0 ( i.e. west Longitude)

Joel

POSTED BY: Joel Tenenbaum

It seems to me that you are feeding ListContourPlot a simple matrix of speed values. This way the frame labels will only note the position within the matrix. To get more meaningful frame labels you should give a list (not a matrix) of triples {pressure, latitude, speed} or whatever. Compare the labels:

ListContourPlot[Table[Sin[i + j^2], {i, -1, 2, 0.1},
  {j, 0, 3, 0.1}]]
ListContourPlot[Flatten[Table[{j, i, Sin[i + j^2]},
   {i, -1, 2, 0.1}, {j, 0, 3, 0.1}], 1]]

As for adding lines on top of the contour plot, I would recommend Epilog:

ListContourPlot[Table[Sin[i + j^2], {i, 0, 3, 0.1}, {j, 0, 3, 0.1}],
 Epilog -> {Line[{{-20, -20}, {20, 20}}]}]
POSTED BY: Gianluca Gorni

When I try emulating your suggestion (to use Flatten), I get an error message

In[67] = wspdLEVshort3 =  Flatten[Table[wspd3d[[klev, jlat, ilon]], {jlat, nlat, 1, -1}, {ilon, 1, nlon, 1}], 1]
Out[67] = {13.7266, 15.414, 21.2157, 24.9529, 30.6142, 31.7384, 32.2047, \
33.6632, 38.2124, 51.1077, 40.0414, 18.06, 17.703, 18.7609, 24.5397, \
31.4082, 37.9464, 42.0565, 43.5092, 42.0817, 51.6718, 52.7562, \
39.4708, 17.4501, 21.3099, 21.0234, 28.2605, 39.5729, 48.4302, \
55.9663, 58.1384, 60.184, 59.1318, 39.6699, 35.4416, 17.9134, \
27.4215, 23.1979, 31.0662, 46.8974, 58.2954, 75.8074, 80.1236, \
71.3519, 50.4602, 40.5332, 42.4953, 15.0675, 33.2243, 27.041, 33.452, \
53.1378, 83.8582, 78.9329, 66.6444, 54.6909, 37.9928, 41.7945, \
47.9264, 11.802, 37.7803, 27.9041, 37.1021, 62.3661, 76.0097, \
60.4854, 47.1717, 33.8486, 36.0846, 43.461, 34.9605, 9.00443, \
41.0756, 31.5089, 41.1696, 70.1772, 62.726, 47.3514, 32.3545, \
33.3947, 42.8117, 48.8211, 23.8703, 14.382, 42.1381, 5031.67, \
44.8849, 66.148, 52.6835, 33.1125, 23.337, 35.1117, 49.8902, 41.995, \
18.2291, 14.5471, 40.3319, 32.73, 46.2485, 58.3091, 36.0893, 21.0668, \
28.6275, 47.8213, 47.8315, 21.2894, 15.0483, 20.5185}

ListContourPlot::arrayerr: {13.7266,15.414,21.2157,24.9529,30.6142,31.7384,32.2047,33.6632,38.2124,51.1077,<<98>>} 

must be a valid array.

The full printout is attached. Because of travel I'm only able to work on this slowly.

Joel

Attachments:
POSTED BY: Joel Tenenbaum

You have probably flattened too much. You have to flatten only to level 1: Flatten[matrix 1], so that you have a list of triples.

POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract