1
$\begingroup$

I want to have the correct labelling of axes in a ListContourPlot that I create via

testTable=Table[x + y, {x, 0, 5}, {y, -5, 5}];

Show[ListContourPlot[testTable,DataRange -> {{0, 5}, {-5, 5}},FrameLabel -> {"x", "y"},PlotLegends -> Automatic]

enter image description here However, I want to have the correct labelling: i.e. 0<x<5 and -5<y<5. How can I do this?

Update:

However, this cannot be correct as e.g. for x->3, y->4 : x+y=-1 !

$\endgroup$
3
  • $\begingroup$ testTable = Table[x + y, {x, 0, 5}, {y, -5, 5}]; Show[ListContourPlot[testTable, DataRange -> {{0, 5}, {-5, 5}}, PlotRange -> All]] $\endgroup$ – cvgmt Sep 23 '20 at 11:09
  • $\begingroup$ This does not make it correct? Please see my update. $\endgroup$ – MrDerDart Sep 23 '20 at 11:31
  • $\begingroup$ testTable = Table[x + y, {x, 0, 5}, {y, -5, 5}]; ListContourPlot[Thread@testTable, DataRange -> {{0, 5}, {-5, 5}}, FrameLabel -> {"x", "y"}, PlotLegends -> Automatic, AspectRatio -> Automatic] $\endgroup$ – cvgmt Sep 23 '20 at 11:50
1
$\begingroup$

Your question's title refers to "axis label" which probably caused many to focus on the FrameTicks. However, I suspect your question actually has to do with the Contours.

Clear["Global`*"]

testTable = Table[x + y, {x, 0, 5}, {y, -5, 5}];

If you do not like the default FrameTicks you must specify your own.

yTicks = DeleteDuplicatesBy[
       Join[
    Table[{y, ToString[y], {0.012, 0.}, {GrayLevel[0.], 
               AbsoluteThickness[0.4]}}, {y, -5, 5}], 
    Table[{y, "", {0.009, 0.}, {GrayLevel[0.], 
               AbsoluteThickness[0.3]}}, {y, -5, 5, 1/2}]], 
   First]; 

If you are not adding options to an existing graphic or combining graphics there is no need for Show.

EDIT: From the documentation, "ListContourPlot[array] arranges successive rows of array up the page, and successive columns across." Consequently, your data should be transposed.

ListContourPlot[Transpose@testTable,
 DataRange -> {{0, 5}, {-5, 5}},
 FrameLabel -> {"x", "y"},
 PlotLegends -> Automatic, 
 FrameTicks -> {{yTicks, yTicks /. _String :> ""}, {Automatic, Automatic}}]

enter image description here

Compare with

ContourPlot[x + y, {x, 0, 5}, {y, -5, 5},
 PlotLegends -> Automatic]

enter image description here

$\endgroup$
0
$\begingroup$
ListContourPlot[testTable,
 DataRange -> {{0, 5}, {-5, 5}},
 FrameLabel -> {"x", "y"}, 
 FrameTicks -> {{Charting`ScaledTicks["Linear"][-5, 5, {10, 5}], Automatic}, 
      {Automatic, Automatic}},
  PlotLegends -> Automatic]

enter image description here

In general, you can use Charting`ScaledTicks["Linear"] as

Charting`ScaledTicks["Linear"][min, max, {maxnumberofmajorticks, maxnumberofminorticks}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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