-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: fig.set_dpi()
and figure.dpi
option in matplotlibrc
file not working
#24644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Do you have a high-dpi screen? |
Yes I sometimes use a high dpi screen but I've noticed this behaviour even when I'm only using my laptop screen (1920×1080) with no external displays connected. |
The source of the problem is this:
Doing [1] matplotlib/lib/matplotlib/backend_bases.py Lines 2117 to 2123 in b2e8434
[2] matplotlib/lib/matplotlib/backend_bases.py Line 1673 in b2e8434
[3] matplotlib/lib/matplotlib/backend_bases.py Line 1673 in b2e8434
So we need at least one more go-around to get this correct. I am going to see what it looks like to:
|
tagging as 3.7 as the amount of changes I am planning I expect to be bigger than what I would like to backport, but can be talked out of that (and probably should wait to see the code before jumping to conclusions anyway). |
Oh, I thought I saw the |
As an update, I took at pass at this and failed. @QuLogic has a plan to fix this at a lower level. |
Just to clarify this a bit, because I think its being muddied by hiDPI and inline issues: dpi set on creation:import matplotlib.pyplot as plt
fig, ax = plt.subplots(dpi=150)
ax.plot([1, 2], [1, 2])
plt.show()
fig.savefig('Boo.png', dpi='figure')
dpi set after creation:fig, ax = plt.subplots()
fig.set_dpi(150)
ax.plot([1, 2], [1, 2])
plt.show()
fig.savefig('Boo.png', dpi='figure')
No doubt because matplotlib/lib/matplotlib/backend_bases.py Line 2301 in a5f5af3
fig._original_dpi .
|
Note that if we just modify It doesn't fix the original issue #11227, which is somewhat orthogonal. |
So far as I can tell, |
|
Bug summary
fig.set_dpi(150)
only changes the dpi of plot shown in the Jupyter notebook but not in the saved figurefigure.dpi
in thematplotlibrc
file does not work at all (EDIT: bug occurs inmatplotlib-inline 0.1.3
but this is fixed inmatplotlib-inline 0.1.6
)plt.subplots(dpi=150)
works as expected and changes the dpi of both the plot shown in the Jupyter notebook as well as in the saved figureContinuation of discussion in #11227
Code for reproduction
Actual outcome
Inside a Jupyter notebook running python 3.10.4 inside a conda environment (no
matplotlibrc
file):Saved plot is at 72.0 dpi.
Inside a standalone Python script running the same python version inside a conda environment (no
matplotlibrc
file):Saved plot is at 100.0 dpi.
Expected outcome
fig.set_dpi(150)
would set the dpi to 150 for the figure shown in the Jupyter notebook + the figure shown in the matplotlib window that pops up whenplt.show()
is called as well as the figure saved.figure.dpi
in thematplotlibrc
file would change the default dpi of figures created (but it does not). From my original comment in #11227:The default dpi should be 100.0 instead of 72.0 (only seems to happen inside Jupyter notebooks and not in standalone python scripts)
(similar to point #1)
fig.savefig("test.png", dpi="figure")
should reflect the changed dpi that was set withfig.set_dpi(150)
. Instead, it saves the figure at 72.0 dpi (when running the code in a Jupyter notebook) or 100.0 dpi (when running the code in a standalone Python script). Both the Jupyter notebook and Python script are running the same Python version in the same conda environment.Additional information
Previous discussion in #11227
Operating system
WSL2 running Ubuntu 20.04.5 LTS
Matplotlib Version
3.5.2
Matplotlib Backend
Inside Jupyter notebook (same regardless whether or not
matplitlibrc
file exists):module://matplotlib_inline.backend_inline
.Inside Python script with no
matplotlibrc
file: QtAggInside Python script with
matplotlibrc
file: TkAgg (since I set my backend to TkAgg in mymatplotlibrc
file)Python version
3.10.4
Jupyter version
6.5.2
Installation
conda 22.9.0
The text was updated successfully, but these errors were encountered: