# Changing Axes Values in MatrixPlot

I have a matrix of values (potentially quite big), which I have decoded into values of -1, 0 and 1 based on some rules. I want to use the MatrixPlot to see the pattern.

My issue is that the MatrixPlot automatically assigns the integer values corresponding to the position in the matrix in my case. However, instead of the (integer) positions, I want to use my own grid (xrow and ycolumn) of the same size on the axes. I have tried to use FrameTicks, but clearly it is a wrong command as it pushed my x and y values to the corner.

rules = {-1 -> Red, 0 -> White, 1 -> Green};
RegWhich = {{-1, 0, 1,1},{0, 0, 0,-1}, {0,0,1,1}};
xrow = Range[0.1, 0.12, 0.01];
ycolumn = Range[0.01, 0.04, 0.01];
MatrixPlot[RegWhich, ColorRules -> rules, Frame -> True, Mesh -> True,
MeshStyle -> Black,
PlotLegends -> SwatchLegend[rules[[All, 2]], rules[[All, 1]]]]


Add the option FrameTicks:

yticks = MapIndexed[{#2[[1]], #} &, xrow];
xticks = MapIndexed[{#2[[1]], #} &,  ycolumn];
MatrixPlot[RegWhich, ColorRules -> rules,
FrameTicks -> {{yticks, yticks}, {xticks, xticks}}, Mesh -> True,
MeshStyle -> Black,
PlotLegends -> SwatchLegend[rules[[All, 2]], rules[[All, 1]]]]


Update: If you want the first row at the bottom of the plot add the option DataReversed -> True to get

Alternatively, you can Reverse the input matrix rows and use DataRange:

MatrixPlot[Reverse@RegWhich, ColorRules -> rules,
DataRange -> {{.01, .04}, {.1, .12}},
FrameTicks -> {{xrow, xrow}, {ycolumn, ycolumn}}, Mesh -> True,
MeshStyle -> Black,
PlotLegends -> SwatchLegend[rules[[All, 2]], rules[[All, 1]]]]


same picture

• Thanks a lot. Another quick question, how can I have the reverse order of the rows (as in, with 0.1 on the bottom corner)? – Natalia K Feb 7 at 10:50
• @NataliaK, please see the update. – kglr Feb 7 at 20:25