I have been having problems with exported plots cutting off a pixel or two of the text in the title of my plots.
Let's assume we have some data (AR(1) noise with a high autoregressive parameter makes good fake economic data):
testdata = FoldList[0.99 #1 + #2 &, 1. ,
RandomVariate[NormalDistribution[0, 0.5], {100}] ];
And a title for our graph. We can try:
title =
Column[{Style["This is a test", 24, Bold, FontFamily -> "Arial", Black],
Style["And so is this", 20, FontFamily -> "Arial", Black]},
Center, 0.3, BaselinePosition -> Top]
which does give a bit of whitespace at the top. We can also try another setting for BaselinePosition
as below. As far as I can tell, all the settings other than Top
look like this.
titleb = Column[{Style["This is a test", 24, Bold, FontFamily -> "Arial", Black],
Style["And so is this", 20, FontFamily -> "Arial", Black]},
Center, 0.3, BaselinePosition -> Baseline]
Now consider what this looks like as a title to a plot:
ListLinePlot[testdata,
BaseStyle -> {FontFamily -> "Arial", FontSize -> 16},
ImageSize -> 400, PlotLabel -> title, Frame -> True,
ImagePadding -> {{Automatic, Automatic}, {Automatic, 1}}]
The linespacing is suddenly a bit wider than required, and there is far too much whitespace above the title. (This would be obvious if the whole plot were Framed
, but if I do that, the next issue doesn't arise, and I don't want a border around the whole plot anyway.)
Now consider the case where the title has BaselinePosition
other than top. Now the linespacing is still wider than the original column, and there is no whitespace at all above the text. This causes problems when I export the graphic (especially to EMF under Windows for use in PowerPoint or Word) because then the top pixel or so of the text is cut off. (This seems to be related to this issue.)
testplotb =
ListLinePlot[testdata,
BaseStyle -> {FontFamily -> "Arial", FontSize -> 16},
ImageSize -> 400, PlotLabel -> titleb, Frame -> True,
ImagePadding -> {{Automatic, Automatic}, {Automatic, 1}}]
If I adjust ImagePadding
, it increases the space between the plot frame and the title, not above the title. I get the same problem even if I change Column
to Grid
or GridBox
with the relevant options. Adjusting Spacings
doesn't seem to work for whitespace at the top of the first element, only for the spacing between rows/elements.
How can I add just a pixel or two to the whitespace between the top of my custom plotlabel and the edge of an exported graphic? Ideally I'd like to keep the linespacing a little tighter, consistent with how it looks outside the plot, as well.
Column
oftitle
and see it's intentionally narrow. But it appears ever so slightly wider when used in thePlotLabel
. So that's the issue I focused my attention on in the answer below: how can the two appearances be kept the same? $\endgroup$