# How can I control the overall size of a labeled plot?

I am creating a bar chart plot and would like to set the overall its over size to be 240 pt, or approx. 85 mm in width and use automatic aspect ratio. Before I add the axes labels, the size looked all right. However, after I add the axes labels with Labeled[...], the oversize became smaller than what I expected.

The codes I used before and after adding the axes labels are

BarChart[spec // N,
ChartLabels -> Placed[list, Above], GridLines -> Automatic,
PlotRange -> {Automatic, {0, 1.2}}, BarSpacing -> 0.5, ImageSize -> 240]


and

Labeled[
BarChart[spec // N,
ChartLabels -> Placed[list, Above], GridLines -> Automatic,
PlotRange -> {Automatic, {0, 1.2}}, BarSpacing -> 0.5, ImageSize -> 240],
{"Harmonic order", "Harmonic mag. [p.u.]"},
{Bottom, Left},
Spacings -> {0.2, -0.2}, RotateLabel -> True]


The bar charts I exported in pdf format and placed side by side with the same percentage display, they look like

Why is the one with axes label much smaller? How do I correctly set the overall size of the second plot to be 240 pt also? Sorry the codes above include some predefined variables, but I guess this is a general question about how to control the overall size of a plot with Labeled[...].

• Although you are asking a general question, it is good practice to include all the definitions needed to make your examples executable by other people so they can generate answers in terms of the those examples. – m_goldberg Jan 24 '17 at 1:43
• Also, you have been asking questions on this site for two months; it is time you learned to format your questions properly. A way of learning how to format is to click on the edit button at the bottom of any well-formated question or answer, and study its formatting. When I was new to this site, I learned a lot about formatting that way. – m_goldberg Jan 24 '17 at 1:49
• Correct response is a duplicate to this answer – Stitch Jan 24 '17 at 18:39

Labeled objects are not treated consistently with other graphics objects in Mathematica, so I would recommend avoiding Labeled for precise work.

To match the appearance of Labeled you can use Frame and FrameLabel:

BarChart[{1, 2, 3}, GridLines -> Automatic, ImageSize -> 240,
Frame -> {True, True, False, False},
FrameLabel -> {"Harmonic order", "Harmonic mag. [p.u.]"}]


Now the whole image will be at the size you specify.

• I think this is what I was looking for. Thanks. – nanjun Feb 26 '17 at 21:10

A very simple solution is to Rasterize them prior to exporting:

spec = {.1, .2, .5, .3, .9};
list = {"a", "b", "c", "d", "e"}
p1 = Rasterize[
BarChart[spec // N, ChartLabels -> Placed[list, Above],
GridLines -> Automatic, PlotRange -> {Automatic, {0, 1.2}},
BarSpacing -> 0.5, ImageSize -> 240], ImageResolution -> 300]
p2 = Rasterize[
Labeled[BarChart[spec // N, ChartLabels -> Placed[list, Above],
GridLines -> Automatic, PlotRange -> {Automatic, {0, 1.2}},
BarSpacing -> 0.5, ImageSize -> 240], {"Harmonic order",
"Harmonic mag. [p.u.]"}, {Bottom, Left}, Spacings -> {0.2, -0.2},
RotateLabel -> True], ImageResolution -> 300]
Export["p1.pdf", p1]
Export["p2.pdf", p2]

• If the Head of p2 was Graphics (as p1), not Labeled, one can use 'set' of ImagePadding + BorderDimensions to make pictures of equal size and to have nice vector pdf images, not raster (although 300 dpi is appropriate). Why MMA gives different types (heads) to similar objects? For simple user both these charts look like Graphics objects. – Alx Jan 24 '17 at 8:56
• @Stitch Sorry, I need the figures to be in vector format and cannot rasterize them. Any idea why the size became so much smaller after adding Labeled? – nanjun Jan 24 '17 at 17:21
• @nanjun Then you have to look here for the exact solution to your problem. Short story -- PrintingStyleEnvironment has to be Working. – Stitch Jan 24 '17 at 18:37
• On the othe hand, if OP uses these plots (*.pdf files) in some document (e.g. LaTeX) they can be scaled without any loss in quality to needed size when placed even if originally they were of different sizes. – Alx Jan 25 '17 at 2:54