1
$\begingroup$

Suppose I have an array plot like this:

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

ArrayPlot[M, FrameTicks -> Automatic]

enter image description here

How can I make it so that the frame ticks are given by a list, like:


x={2,4,6,8,10,12,14,16,18,20};

y={10,11,12,13,14};

$\endgroup$
3
$\begingroup$
SeedRandom[1]
M = RandomReal[1, {5, 10}];
x = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};
y = {10, 11, 12, 13, 14};

{xticks, yticks} = MapIndexed[{#2[[1]], #} &, #] & /@ {x, y};

ArrayPlot[M, FrameTicks -> {{yticks, yticks}, {xticks, xticks}}]

enter image description here

You can also use

{yticks2, xticks2} = Thread /@ Thread[{Range[Dimensions[M]], {y, x}}];

{yticks2, xticks2} == {yticks, xticks}
 True

Alternative approach is to reverse the rows of M and use the options DataRange and DataReversed and use {{y,y},{x,x}} as FrameTicks:

ArrayPlot[Reverse @ M, 
 DataReversed -> True, 
 DataRange -> MinMax /@ {x, y}, 
 FrameTicks -> {{y, y}, {x, x}}, 
 AspectRatio -> 1/2]

enter image description here

$\endgroup$
2
  • $\begingroup$ Image are not identical? $\endgroup$ Mar 3 at 21:39
  • $\begingroup$ Thank you @OkkesDulgerci. Updated to get identical images. $\endgroup$
    – kglr
    Mar 3 at 22:11

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.