0
$\begingroup$

I have the following ArrayPlot:

M = RandomReal[1, {5, 9}];

ArrayPlot[M, FrameTicks -> Automatic, DataRange -> {{11, 19}, {1, 5}},
  AspectRatio -> 1/2]

enter image description here

Now, I wanted to use PlotRange to plot only the columns 12 to 18, so I tried this:

ArrayPlot[M, FrameTicks -> Automatic, DataRange -> {{11, 19}, {1, 5}},
  AspectRatio -> 1/2, PlotRange -> {{12, 18}, All}]

enter image description here

But when I do this, a part of the plot is cut off because the numbers in PlotRange are not interpreted as the orders of the columns. Is there a way that I can select the orders of the columns I want to be ploted ?

Is there a way, for example, that the orders of the columns are given by a list, like, in this case, x={11,12,13,14,15,16,17,18,19,20}, and I can use this to select just 12 to 18? That would be great.

$\endgroup$
2
  • $\begingroup$ PlotRange -> {{11.5, 18.5}, All} or PlotRange -> {{11.5, 18.5}, {0.5, 5.5}}? $\endgroup$ Mar 4, 2021 at 15:49
  • $\begingroup$ Yeah I guess this works for plotting this particular exemple but I really wanted to be able to select the rows I need to plot by the numbers I give to the rows. $\endgroup$ Mar 4, 2021 at 15:58

1 Answer 1

2
$\begingroup$
SeedRandom@2
M = RandomReal[1, {5, 9}];
{r, c} = Dimensions@M;
xTicks = Transpose@{Range@c, 10 + Range@c};
yTicks = Transpose@{Range@r, 0 + Range@r};
ArrayPlot[M, FrameTicks -> {{yTicks, yTicks}, {xTicks, xTicks}}, 
 DataReversed -> True]

enter image description here

m2 = M[[All, 2 ;; 8]];
{r, c} = Dimensions@m2;
xTicks = Transpose@{Range@c, 11 + Range@c};
yTicks = Transpose@{Range@r, 0 + Range@r};
ArrayPlot[m2, FrameTicks -> {{yTicks, yTicks}, {xTicks, xTicks}}, 
 DataReversed -> True]

enter image description here

m2 = M[[2 ;; 4, 2 ;; 8]];
{r, c} = Dimensions@m2;
ticks[xStart_, yStart_] := {Transpose@{Range@r, yStart + Range@r - 1},
   Transpose@{Range@c, xStart + Range@c - 1}}
ArrayPlot[m2, FrameTicks -> Transpose@{ticks[12, 6], ticks[12, 6]}, 
 DataReversed -> True]

enter image description here

$\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.