Skip to content

Create a matplotlibrc file #36

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

Closed
dstansby opened this issue May 7, 2022 · 8 comments
Closed

Create a matplotlibrc file #36

dstansby opened this issue May 7, 2022 · 8 comments
Labels
good first issue Good for newcomers New feature New feature or request
Milestone

Comments

@dstansby
Copy link
Member

dstansby commented May 7, 2022

Currently we set style options using several lines of code:

mpl.rc("axes", edgecolor="white")
mpl.rc("axes", facecolor="#262930")
mpl.rc("axes", labelcolor="white")
mpl.rc("savefig", facecolor="#262930")
mpl.rc("text", color="white")

Instead we should put these in a matplotlibrc file, to reduce lines of code, and make it easier to edit and see what style settings are being set all in one go.

@dstansby dstansby added New feature New feature or request good first issue Good for newcomers labels May 7, 2022
@kevinyamauchi
Copy link
Contributor

Hey @dstansby ! Sorry for my ignorance of how matplotlib configs work, but is setting the configs in this manner "global"? One common use case in napari is people launch a viewer from a jupyter notebook and I think we want to make sure that styling changes made in the plot do not affect styling of plots in the notebook.

@jo-mueller
Copy link
Contributor

Just tried adding a mplstyle file to the repo but this changes plotting in Jupyterlab as well :/

@dstansby
Copy link
Member Author

dstansby commented May 9, 2022

I think the way to fix that is use the instructions at https://matplotlib.org/stable/tutorials/introductory/customizing.html#temporary-rc-settings to use a context manager inside napari-matplotlib.

@jo-mueller
Copy link
Contributor

Thanks for the link - would you then add the decorator to every call to the draw() function in the derived widget(s)? Sorry, I haven't worked much with more intricate matplotlib designs, neither.

@dstansby
Copy link
Member Author

dstansby commented May 9, 2022

I think it would be sufficient to put a context manager around this line:


and also anywhere a new Axes is created in the non-base widgets.

@jo-mueller
Copy link
Contributor

jo-mueller commented May 19, 2022

Thanks @dstansby ,

I tried a few things and it seems that the context manager has to go where the axes object is created, for instance here in the Histogram widget:

self.axes = self.canvas.figure.subplots()

Putting it around/into the _draw statement will only alter parameters (apparently) that have not already been set yet at the time of drawing (e.g., axes background)

@jo-mueller
Copy link
Contributor

Hi @dstansby, I think this was fixed by #65. The point of a rc file was to not have to set the colors of labels/spines/etc one by one but do it globally. Having this in the set_default_colorscheme function makes this irrelevant, I believe.

@dstansby dstansby added this to the 0.3.0 milestone May 18, 2023
@dstansby
Copy link
Member Author

Going to close this, since work ongoing in other issues and PRs covers this.

@dstansby dstansby closed this as not planned Won't fix, can't repro, duplicate, stale Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers New feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants