Dpi parameter controlling size of plot display in Jupyter Notebook?

I’ve encountered some weird behavior when using Plots.jl. I’d like to know if this is a bug. Consider the following code:

using Plots; gr()
x = collect(0:0.1:50)
y = sin.(x)
plot(x,y, dpi = 50)

With dpi = 50 the plot looks like this:

Now setting dpi = 100 drastically increases the size of the plot:

And at dpi = 200 the plot can’t even fit on the screen:

According to the documentation, dpi controls the “Dots Per Inch of output figures.” Indeed, when I use savefig(C:/Users/my/file/path), it’s clear that the dpi parameter does control the resolution of figures when they are saved. But why is it also controlling the size of the plot display in the notebook? I have tried to control the size using the size() parameter, but when dpi is specified size() seems to have no effect whatsoever on the plot size…

So is this a bug with Plots.jl? I’d really like to be able to adjust the plot resolution without changing the display size in the notebook.


Looking into the code and how this is passed on to the GR backend, we see that Plots.DPI is hard coded to 100 and the given DPI is then used to calculate a ratio.

This gets then passed to GR via gr_setwsviewport:

1 Like