Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]:fig.set_dpi() andfigure.dpi option inmatplotlibrc file not working #24644

Open
@BearBearCodes

Description

@BearBearCodes

Bug summary

  • fig.set_dpi(150) only changes the dpi of plot shown in the Jupyter notebook but not in the saved figure
  • figure.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 figure

Continuation of discussion in#11227

Code for reproduction

importmatplotlibasmplimportmatplotlib.pyplotaspltfig,ax=plt.subplots()fig.set_dpi(150)ax.plot([1,2], [1,2])print(fig.get_dpi())print(mpl.rcParams["figure.dpi"])print(mpl.rcParams["savefig.dpi"])fig.savefig("test.png",dpi="figure")plt.show()

Actual outcome

Inside a Jupyter notebook running python 3.10.4 inside a conda environment (nomatplotlibrc file):

15072.0figure

image
Saved plot is at 72.0 dpi.

Inside a standalone Python script running the same python version inside a conda environment (nomatplotlibrc file):

150100.0figure

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:

    Moreover, I'm finding that on my machine, thefigure.dpi rcParam is not respected after I have modified it in mymatplotlibrc file (located at~/.config/matplotlib/matplotlibrc). Other changes to options likeaxes.prop_cycle in mymatplotlibrc file are being reflected in the plots shown in the Jupyter notebook as well as in those saved viafig.savefig(), but changes to thefigure.dpi option are not reflected in the plots shown/saved

  • 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 notmatplitlibrc file exists):module://matplotlib_inline.backend_inline.

Inside Python script with nomatplotlibrc file: QtAgg

Inside Python script withmatplotlibrc 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp