# Between own axes around ArrayPlot white borders occur

I have an ArrayPlot:

plot = ArrayPlot[RandomReal[1, {10, 20}], ColorFunction -> "Rainbow",
Frame -> None] Now I want to plot axes around the plot labeled with numbers from my own plot range:

Graphics[Inset[plot, Scaled[{.5, .5}], Automatic, Scaled],
Frame -> True, PlotRange -> {{11.5, 14.5}, {0.4, 0.8}},
AspectRatio -> ImageAspectRatio@plot]


I used here the solution from @Kuba in this question. How can I stretch the plot so that it fits into the frame without white borders, preserving the aspect ratio?

For minimal modification to your code zero PlotRangePadding and ImagePadding in the Inset:

Graphics[
Inset[
Show[plot, PlotRangePadding -> 0, ImagePadding -> 0],
Scaled[{.5, .5}], Automatic, Scaled
]
, Frame -> True
, PlotRange -> {{11.5, 14.5}, {0.4, 0.8}}
, AspectRatio -> ImageAspectRatio @ plot
] Alternatively construct the needed DataRange in ArrayPlot:

rangeFn[{{x_, X_}, {y_, Y_}}, {h_, w_}] :=
{{x + (X - x)/(2 w), X - (X - x)/(2 w)},
{y + (Y - y)/(2 h), Y - (Y - y)/(2 h)}}

data = RandomReal[1, {10, 20}];

range = rangeFn[{{11.5, 14.5}, {0.4, 0.8}}, Dimensions@data];

p2 = ArrayPlot[data
, ColorFunction -> "Rainbow"
, DataRange -> range
, AspectRatio -> 1/2
, PlotRangePadding -> None
];

Show[p2, FrameTicks -> Automatic] Notes:

• Show is necessary here as adding FrameTicks to the ArrayPlot expression does not yield a reasonable tick spacing.
• rangeFn is needed to counteract "For ArrayPlot, the settings for DataRange refer to the coordinates of the centers of each cell."
• Thanks a lot … but I still see in my Graphics output a very small white gap above the lower horizontal axis and also left from the right vertical axis. I am using Mathematica 11.3.0.0 – mrz Jul 24 '18 at 11:46
• @Lenoil please try using Inset[Show[plot, PlotRangePadding -> 0, ImagePadding -> 0, ImageMargins -> 0], Scaled[{.5, .5}], Automatic, Scaled] and report the result. – Mr.Wizard Jul 24 '18 at 11:51
• Mr.Wizard this is the solution … thank you. – mrz Jul 24 '18 at 11:57
• @Lenoil Glad I could help! :-) I think ImageMargins is not needed so I left that out of my revised answer; please let me know if this is incorrect. I also added an alternative approach you may consider. – Mr.Wizard Jul 24 '18 at 12:03
• I tried both of your solutions and they work as you wrote. Thank you for the notes. – mrz Jul 24 '18 at 13:30
Graphics[
Inset[plot, Scaled[{.5, .5}], Automatic, Scaled[1.072]],
Frame -> True,
PlotRange -> {{11.5, 14.5}, {0.4, 0.8}},
AspectRatio -> ImageAspectRatio@plot]

• Thank you but the factor 1.072 from where did you get it? I need some general solution. – mrz Jul 24 '18 at 10:59