Plots.jl set figure size for LaTeX publications

A way to achieve this is using the pgfplots backend to save the figure into a tikzpicture.

Instead of adjusting the size before you produce the plot, you can adjust the size in the generated .tex file. By using the package pgfplots in LaTeX, the plot will be drawn directly in the PDF, where you can adjust the size, fonts, colors, and any other property you can think of.

An example:

using Plots; pgfplots() # Need to add PGFPlots first
plot(1:3)
savefig("example.tex")

I personally do not like the output the juliaplots for the .tex files, as they seem a bit messy to me, but here the first line has the height and you can also specify a width:

\begin{tikzpicture}[]
\begin{axis}[height = {101.6mm}, ylabel = {}, xmin = {0.94}, xmax = {3.06}, ymax = {3.06}, xlabel = {}, unbounded coords=jump,scaled x ticks = false,xlabel style = {font = {\fontsize{11 pt}{14.3 pt}\selectfont}, color = {rgb,1:red,0.00000000;green,0.00000000;blue,0.00000000}, draw opacity = 1.0, rotate = 0.0},xmajorgrids = true,xtick = {1.0,1.5,2.0,2.5,3.0},xticklabels = {$1.0$,$1.5$,$2.0$,$2.5$,$3.0$},xtick align = inside,xticklabel style = {font = {\fontsize{8 pt}{10.4 pt}\selectfont}, color = {rgb,1:red,0.00000000;green,0.00000000;blue,0.00000000}, draw opacity = 1.0, rotate = 0.0},x grid style = {color = {rgb,1:red,0.00000000;green,0.00000000;blue,0.00000000},
draw opacity = 0.1,
line width = 0.5,
solid},axis x line* = left,x axis line style = {color = {rgb,1:red,0.00000000;green,0.00000000;blue,0.00000000},
draw opacity = 1.0,
line width = 1,
solid},scaled y ticks = false,ylabel style = {font = {\fontsize{11 pt}{14.3 pt}\selectfont}, color = {rgb,1:red,0.00000000;green,0.00000000;blue,0.00000000}, draw opacity = 1.0, rotate = 0.0},ymajorgrids = true,ytick = {1.0,1.5,2.0,2.5,3.0},yticklabels = {$1.0$,$1.5$,$2.0$,$2.5$,$3.0$},ytick align = inside,yticklabel style = {font = {\fontsize{8 pt}{10.4 pt}\selectfont}, color = {rgb,1:red,0.00000000;green,0.00000000;blue,0.00000000}, draw opacity = 1.0, rotate = 0.0},y grid style = {color = {rgb,1:red,0.00000000;green,0.00000000;blue,0.00000000},
draw opacity = 0.1,
line width = 0.5,
solid},axis y line* = left,y axis line style = {color = {rgb,1:red,0.00000000;green,0.00000000;blue,0.00000000},
draw opacity = 1.0,
line width = 1,
solid},    xshift = 0.0mm,
    yshift = 0.0mm,
    axis background/.style={fill={rgb,1:red,1.00000000;green,1.00000000;blue,1.00000000}}
,legend style = {color = {rgb,1:red,0.00000000;green,0.00000000;blue,0.00000000},
draw opacity = 1.0,
line width = 1,
solid,fill = {rgb,1:red,1.00000000;green,1.00000000;blue,1.00000000},fill opacity = 1.0,text opacity = 1.0,font = {\fontsize{8 pt}{10.4 pt}\selectfont}},colorbar style={title=}, ymin = {0.94}, width = {152.4mm}]\addplot+ [color = {rgb,1:red,0.00000000;green,0.60560316;blue,0.97868012},
draw opacity = 1.0,
line width = 1,
solid,mark = none,
mark size = 2.0,
mark options = {
            color = {rgb,1:red,0.00000000;green,0.00000000;blue,0.00000000}, draw opacity = 1.0,
            fill = {rgb,1:red,0.00000000;green,0.60560316;blue,0.97868012}, fill opacity = 1.0,
            line width = 1,
            rotate = 0,
            solid
        }]coordinates {
(1.0, 1.0)
(2.0, 2.0)
(3.0, 3.0)
};
\addlegendentry{y1}
\end{axis}

\end{tikzpicture}

Using the standalone class (for example), the code above generates this figure (which I converted from PDF to PNG to upload it here):
test__Copy_

Finally, when using PGFPlots within a LaTeX document and you have settled on the size/look, you can use TikZ external library to print the figure into a standalone PDF with the size you have already selected, and that you can include directly into your document. This will make the compilation of the document a lot faster in many cases, specially when the figures need lots of points to be drawn.

Hope this helps!

3 Likes