0
$\begingroup$

I am trying to plot co Contour Plots for Tempereature data given in 2D Space (X,Z) in Mathematica. The data is read from CSV file. I have a code that I thinks should work fine, but it plots something outrages. Please help to correct my code. It is below

SetDirectory["G:\\FGCI Staff\\Madyarova\\Mathematica\\Contour Plots"];

dataContour = Import["DataToPlot 90.csv"];    
len = Length[dataContour];

TemeratureChange = dataContour[[2 ;; len, 11]];    
Zm = dataContour[[2 ;; len, 3]];
Xm = dataContour[[2 ;; len, 9]];    
data1 = Table[{ TemeratureChange[[i]], Xm[[i]], Zm[[i]]}, {i, 1, 
    len - 1}];    
ListContourPlot[Transpose[data1], PlotLegends -> Automatic, 
 Contours -> 30, ColorFunction -> Hue, 
 AxesLabel -> {"x axis", "y axis"}, AxesLabel -> {"x", "y"}, 
 PlotLabel -> "Temperature Change (oC)"]

This code plots this enter image description here

I am expecting to see contour plot similar to this enter image description here. The last picture was ploted in Grapher.

What is wring with Mathematica code above? Thank you.

Best wishes, Maria

$\endgroup$
  • 1
    $\begingroup$ Have you looked at your data? What numbers correspond with the vertical black lines? $\endgroup$ – GerardF123 Nov 8 '18 at 15:42
  • $\begingroup$ Without seeing the data, I'd expect that you want {Xm[[i]], Zm[[i]], TemeratureChange[[i]]} – the values corresponding to contours is #3 in the data. But the use of Transpose is also confusing to me, since it looks like data1 should already be the list of {x, y, z} triples the ListContourPlot wants. $\endgroup$ – Brett Champion Nov 8 '18 at 15:52
  • $\begingroup$ Temperature is changing {from -3.8 to 2.6}. My X coordinate is changing within the range {-98 to 98 }. My Y coordinate is changing within the range {-5 to 235 }. I don't know exactly what black lines are $\endgroup$ – Mary Madyarova Nov 8 '18 at 15:54
  • $\begingroup$ @MaryMadyarova I think this will help: mathematica.stackexchange.com/help/merging-accounts $\endgroup$ – Kuba Nov 8 '18 at 17:02
  • $\begingroup$ Once you do this please take a look at asking guidelines. $\endgroup$ – Kuba Nov 9 '18 at 7:33
5
$\begingroup$

It looks like you're doing something like

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

enter image description here

when you really want

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

enter image description here

With the transposed data, ListContourPlot treats it as an array of heights instead of {x, y, z} triples.

(You can ignore the Flatten in my code above, it's just there to get a list of triples instead of an 2D array of them.)

So I think what you're really looking for is

data1 = Table[{Xm[[i]], Zm[[i]], TemeratureChange[[i]]}, {i, 1, len - 1}];    
ListContourPlot[data1, <options>]
$\endgroup$
  • $\begingroup$ Brett Champion, I have changed the last two lines how you proposed and it looks better now. data1 = Table[{ Xm[[i]], Zm[[i]], TemeratureChange[[i]]}, {i, 1, len - 1}]; ListContourPlot[data1, PlotLegends -> Automatic, ColorFunction -> Hue, AxesLabel -> {"x axis", "y axis"}, AxesLabel -> {"x", "y"}, PlotLabel -> "Temperature Change (oC)"] Do you know why I have this white color in the middle of the plot and why axis labels {"x", "y"} are not on the plot? ![enter image description here](i.stack.imgur.com/8BHgV.png) $\endgroup$ – Mary Madyarova Nov 8 '18 at 16:05
  • $\begingroup$ Brett Champion, It works. Thank you so much! The important question now is: "Is there a way to specify colorbar on the legend from -4 to 1 and have colors from red to blue, respectively?" Also, how to reverse an Yaxis and specify X axis from 0 to 28. $\endgroup$ – Mary Madyarova Nov 8 '18 at 17:02
  • $\begingroup$ Here's a dump of things to look up: (1) PlotLegends and BarLegend; (2) ColorFunction, ColorFunctionScaling, Blend, and ColorData; (3) ScalingFunctions; (4) PlotRange. Combination of this site, subsections of the ListContourPlot docs, and individual docs pages (eg. ref/BarLegend) should be useful. $\endgroup$ – Brett Champion Nov 8 '18 at 20:33
  • $\begingroup$ I have modified the code slightly. It is showing me nice results. But I am having hard time inversing the Y axis - I need Y ahis to change from 0 (top) to 180 (bottom). Brett Champion, would you know how to do it? Why ScalingFunction is not working? Thank you. SetDirectory["G:\\FGCI Staff\\Madyarova\\Mathematica\\Contour Plots"]; dataContour = Import["DataToPlot 90.csv"]; len = Length[dataContour]; legendwidth = 500; plotheights = 500; TemeratureChange = dataContour[[2 ;; len, 11]]; Zm = dataContour[[2 ;; len, 3]]; Xm = dataContour[[2 ;; len, 9]]; data1 = Table[{ Xm[[i]], Zm[[i]], TemeratureCh $\endgroup$ – Mary Madyarova Nov 8 '18 at 23:53
  • 2
    $\begingroup$ @MaryMadyarova Please stop posting follow-up questions as answers. If you follow the link I have given in the comment below the question you will be able to merge your accounts and post comments under Brett's answer. $\endgroup$ – Kuba Nov 9 '18 at 7:30

protected by Kuba Nov 9 '18 at 7:33

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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