Skip to content

Add Tidy3D Matplotlib Styles on Import#2428

Merged
frederikschubertflex merged 26 commits into
developfrom
frederikschubertflex/rcparams
May 23, 2025
Merged

Add Tidy3D Matplotlib Styles on Import#2428
frederikschubertflex merged 26 commits into
developfrom
frederikschubertflex/rcparams

Conversation

@frederikschubertflex
Copy link
Copy Markdown
Contributor

@frederikschubertflex frederikschubertflex commented May 6, 2025

This PR addresses #1713 and sets the global Matplotlib styles via the rcParams to a basic set of styles that follow that Flexcompute design brand.

before_style_update
after_style_update

The reset_previous_style function is not yet exported as part of the public API.

Note: The PR also contains a refactoring commit that converts the Flexcompute color map to simple hex strings and refactors the single place that used the hex numbers (tidy3d/material_library/util.py) to simplify the code.

Closes #1713

@frederikschubertflex
Copy link
Copy Markdown
Contributor Author

frederikschubertflex commented May 6, 2025

This PR might need more testing over a broader set of notebooks to see if the new styles break anything. The example is taken from https://github.com/flexcompute/tidy3d-notebooks/blob/develop/Simulation.ipynb. Additionally, the style presets are quite minimal for now and can (should) be extended to improve the display of the plots.

@daquinteroflex
Copy link
Copy Markdown
Collaborator

daquinteroflex commented May 6, 2025

Overall looking great @frederikschubertflex thanks for this!

@tomflexcompute do you have any other preferences for an improved standard tidy3d style? Like thicker axes, etc. We can add this in here.

@daquinteroflex
Copy link
Copy Markdown
Collaborator

daquinteroflex commented May 6, 2025

So the reset styles functionality needs to be added to the changelog.md and also to somewhere in the sphinx documentation too

Comment thread tests/test_components/test_viz.py Outdated
Comment thread tidy3d/material_library/util.py
@frederikschubertflex
Copy link
Copy Markdown
Contributor Author

So the reset styles functionality needs to be added to the changelog.md and also to somewhere in the sphinx documentation too

I added an entry in the CHANGELOG.md but we need to discuss where to document it in the sphinx docs.

@frederikschubertflex frederikschubertflex marked this pull request as ready for review May 8, 2025 12:39
Comment thread tidy3d/components/viz.py Outdated
@frederikschubertflex frederikschubertflex changed the title Add Tidy3D Matplotlib Styles on Import WIP: Add Tidy3D Matplotlib Styles on Import May 16, 2025
@frederikschubertflex frederikschubertflex changed the title WIP: Add Tidy3D Matplotlib Styles on Import Add Tidy3D Matplotlib Styles on Import May 19, 2025
Copy link
Copy Markdown
Collaborator

@yaugenst-flex yaugenst-flex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @frederikschubertflex overall looks great, just a couple of minor comments.

One general comment/question I had is whether it would make sense to create a custom matplotlib style sheet that we could just load on import? Not sure if that's better or not.

Comment thread tidy3d/components/viz/flex_color_paletes.py
Comment thread tidy3d/components/viz/flex_style.py Outdated
Comment thread tidy3d/components/viz/flex_style.py Outdated
@frederikschubertflex
Copy link
Copy Markdown
Contributor Author

One general comment/question I had is whether it would make sense to create a custom matplotlib style sheet that we could just load on import? Not sure if that's better or not.

Good point! I was also thinking about this but did not want to add the complexity of distributing a separate style file. This was the approach with the least amount of friction, but I am happy to change it if you feel more comfortable with the external style sheet approach.

@yaugenst-flex
Copy link
Copy Markdown
Collaborator

Good point! I was also thinking about this but did not want to add the complexity of distributing a separate style file. This was the approach with the least amount of friction, but I am happy to change it if you feel more comfortable with the external style sheet approach.

Is there something that needs to be done beyond just having it live in the viz/ folder? But yeah I agree if it significantly changes in how we have to package then it's not worth it (for the moment at least).

And actually one more question: Do we have some sample plots (or notebook runs) that show the new styles?

Comment thread tidy3d/components/viz/flex_color_palletes.py
@frederikschubertflex
Copy link
Copy Markdown
Contributor Author

frederikschubertflex commented May 20, 2025

Is there something that needs to be done beyond just having it live in the viz/ folder? But yeah I agree if it significantly changes in how we have to package then it's not worth it (for the moment at least).

No, you are correct! We can use it as mpl.style.use("tidy3d.viz.style") if we put a file at tidy3d/viz/style.mplstyle. So its not a large change. What do you think?

@frederikschubertflex
Copy link
Copy Markdown
Contributor Author

frederikschubertflex commented May 20, 2025

I will add a few examples. Note, that many plots such as field data and simulation structures are not affected due to their manual color palettes.

VizData

Old

VizData_old

New

VizData_new

FullyAnisotropic

Old

FullyAnisotropic_old

New

FullyAnisotropic_new

@yaugenst-flex
Copy link
Copy Markdown
Collaborator

No, you are correct! We can use it as mpl.style.use("tidy3d.viz.style") if we put a file at tidy3d/viz/style.mplstyle. So its not a large change. What do you think?

I feel like it might be worth it then. It'll be easier to reuse down the line, since the style might make it into other packages too or perhaps we can even expose it to users if they want to use it.

@frederikschubertflex
Copy link
Copy Markdown
Contributor Author

I changed the setup to use the mplstyle file. I had to add an entry to the pyproject.toml file but I think it should be fine.

Comment thread pyproject.toml Outdated
Comment thread tidy3d/style.mplstyle
Copy link
Copy Markdown
Collaborator

@daquinteroflex daquinteroflex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this very comprehensive upgrade! Looks good to me apart from the question I asked on the cycler, to be sure those are the colors we want?

@daquinteroflex
Copy link
Copy Markdown
Collaborator

We'll of course need to do the notebooks PR after this is merged to develop maybe before the next release.

@daquinteroflex
Copy link
Copy Markdown
Collaborator

Happy to merge whenever imo! Maybe we should run notebooks after #2433 is merged though to catch any issues with that

Comment thread CHANGELOG.md Outdated
Copy link
Copy Markdown
Collaborator

@yaugenst-flex yaugenst-flex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@frederikschubertflex frederikschubertflex enabled auto-merge (squash) May 23, 2025 15:36
@frederikschubertflex frederikschubertflex merged commit 882e730 into develop May 23, 2025
9 checks passed
@frederikschubertflex frederikschubertflex deleted the frederikschubertflex/rcparams branch May 23, 2025 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🎨 Custom tidy3d.rcparams that activates automatically for nicer custom standard plots

4 participants