I would like to create a plot made of subplots containing ArrayPlots with colorbars.
Since Mathematica's native colorbars are still a pain to be placed correctly, I am using an adapted custom one from this question: Sizing cells in a GraphicsGrid/GraphicsRow:
colorbar[{min_, max_}, ticks_, fs_, is_, colorFunction_]:=
DensityPlot[y, {x, 0, 0.1}, {y, min, max},
AspectRatio -> 30,
ColorFunction -> colorFunction,
Frame -> True, FrameLabel -> {{None, None}, {None, None}},
FrameStyle -> Directive[Black, AbsoluteThickness[2]],
FrameTicks -> {{None, {#[[1]], #[[2]], {0, 0.5}} & /@ ticks}, {None,
None}},
FrameTicksStyle -> Directive[FontFamily -> "Helvetica", fs, Black],
ImageSize -> {Automatic, is}, MaxRecursion -> 0, PlotRangePadding -> 0,
PlotPoints -> {2, 100}
]
A minimal example of the plot I am working on is:
{is, fs} = {400, 20};
fsColorbar = fs;
plotops2d = {
FrameLabel -> {"y", "x"},
FrameStyle -> Directive[AbsoluteThickness[2], Black, fs, FontFamily -> "Helvetica"],
FrameTicks -> {All, All, None, None},
ImagePadding -> {{60, 10}, {63, 10}},
ImageSize -> {Automatic, is},
PlotRangePadding -> None, PlotRange -> All,
RotateLabel -> False
};
plot1 = Row[{
ArrayPlot[RandomReal[{0, 1}, {30, 30}], ColorFunction -> "Rainbow", Evaluate[plotops2d]],
Show[colorbar[{0, 1}, {{0, 0}, {1, 1}}, fsColorbar, is, "Rainbow"], ImageSize -> {Automatic, is}, ImagePadding -> {{1, 42}, {63, 10}}]
}];
plot2 = Row[{
ArrayPlot[RandomReal[{0, 1}, {30, 30}], ColorFunction -> "SunsetColors", Evaluate[plotops2d]],
Show[colorbar[{0, 1}, {{0, 0}, {1, 1}}, fsColorbar, is, "SunsetColors"], ImageSize -> {Automatic, is}, ImagePadding -> {{1, 42}, {63, 10}}]
}];
pic = Grid[{{plot1}, {plot2}}]
This results in this nice plot:
However, if I would like to antialias the image with:
pic2 = Rasterize[pic, ImageResolution -> 300]
I get:
I can get the correct alignment if I decrease the values for ImageResolution or ImageSize. However, this is not an option for me. Does anyone what the reason for that behavior is and how I can circumvent it?
GraphicsColumn[]
too? $\endgroup$fsColorbar
mean to befs
(or vice versa)? $\endgroup$fs = fsColorbar
. $\endgroup$GraphicsColumn
looks even worse. It crops more than half of the image for some reason $\endgroup$