4
$\begingroup$

Working on Mathematica 11.3, I find that the vertical axis (more precisely its ticks) is reversed by DataRange which should not happen, e.g.

nmax = 100;
ArrayPlot[Table[x + y, {x, 0, nmax}, {y, 0, nmax}], PlotLegends -> True, FrameTicks -> Automatic]
ArrayPlot[Table[x + y, {x, 0, nmax}, {y, 0, nmax}], PlotLegends -> True, FrameTicks -> Automatic, DataRange -> {{0, nmax}, {0, nmax}}]

Resulting in

ArrayPlot w/o manual DataRange

ArrayPlot w/  manual DataRange

I want a plot like in the first picture but with arbitrarily chosen DataRange and do not want to have the data reversed along the vertical direction (as in ListDensityPlot). Both axes should start at the top left corner. I found a workaround using manual setting of frame ticks but that is not nice. Is their a simple solution?

$\endgroup$
  • $\begingroup$ I also think this shouldn't happen. You could use Take to select which data range you want in this case. $\endgroup$ – Ruud3.1415 Aug 30 '18 at 15:27
  • $\begingroup$ @Ruud3.1415 Sorry, could you give an example of how you would use Take in this context? $\endgroup$ – Pankrat Aug 31 '18 at 14:11
  • $\begingroup$ ‘Take[Table[x+y.....],{{0,nmax},{0,nmax}}]’? $\endgroup$ – Ruud3.1415 Aug 31 '18 at 14:15
  • $\begingroup$ @Ruud3.1415 Ah,ok. Thanks. $\endgroup$ – Pankrat Aug 31 '18 at 14:27
4
$\begingroup$

This is a non-intuitive, but expected behavior. It just comes down to how do you interpret DataRange. See the additional option DataReversed

ArrayPlot[Table[x + y, {x, 0, nmax}, {y, 0, nmax}], 
 PlotLegends -> True, FrameTicks -> Automatic, 
 DataRange -> {{0, nmax}, {0, nmax}}, DataReversed -> True]
ArrayPlot[Reverse@Table[x + y, {x, 0, nmax}, {y, 0, nmax}], 
 PlotLegends -> True, FrameTicks -> Automatic, 
 DataRange -> {{0, nmax}, {0, nmax}}, DataReversed -> True]

enter image description here enter image description here

The underling reason is, that usually matrix indexes start from top left, while plot coordinates from left bottom. The function named ArrayPlot has to bring these two worlds together.

$\endgroup$
  • $\begingroup$ Ahhh... first I misunderstood you answer. You reversed both using an option of ArrayPlot and the data itself. Seems to work. Thanks. $\endgroup$ – Pankrat Aug 31 '18 at 14:13

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.