Plots.jl set figure size for LaTeX publications

Hi @kmundnic!

Thanks for this awesome answer! I had a look in the repository(GitHub - kmundnic/pgfplots-example: An example of PGFPlots in LaTeX) already. Thanks a lot! I will open an issue there in case I have any further questions.

In case people are visiting this thread with a similar question, I will post the answert to my initial question. I digged in the source code a bit and worked out, how Plots.jl is setting thefigure size for the pyplot backend. They use an internal DPI value of 100, set by the constant DPI, found in … . The first line in the function _create_backend_figure in pyplot.jl tells the story:

w,h = map(px2inch, Tuple(s * plt[:dpi] / Plots.DPI for s in plt[:size]))

The size of the figure set by Plots.jl size argument is in pixels and then converted to inch using the DPI value of dpi( which can be set via plot(dpi=100)).
If you do not want to safe in a pixelformat, you do not have to care about the DPI value. Converting from pts to the correct inches works as follows:

width_pts = 246.0  # or any other value
inches_per_points = 1.0/72.27
width_inches = width_pts *inches_per_points
width_px= width_inches*100  # or  width_inches*DPI

Setting plot(size=(width_px, width_px)) now creates a square plot with exactly 246 points.

8 Likes