Skip to content
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

How does this compare to the official matplotlib stylesheet? #15

Closed
mazzma12 opened this issue Aug 22, 2022 · 4 comments
Closed

How does this compare to the official matplotlib stylesheet? #15

mazzma12 opened this issue Aug 22, 2022 · 4 comments
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@mazzma12
Copy link

mazzma12 commented Aug 22, 2022

This article shows how to use it https://www.datafantic.com/the-magic-of-matplotlib-stylesheets/.
Despite the format which is different it looks like it is another way to do do a declarative templating

@mazzma12 mazzma12 changed the title How does this compare to the official matplotlib stylesheet How does this compare to the official matplotlib stylesheet? Aug 22, 2022
@lgienapp
Copy link
Owner

aquarel is a wrapper around the stylesheets, so everything you can do with stylesheets can be achieved with aquarel. However there are some notable shortcomings of stylesheets that aquarel adresses:

  1. On-the-fly templating – the stylesheets are applied once and are then used for every plot in the current plotting context (py-file, notebook, ipython session, ...). aquarel takes a different approach here and aims to provide per-plot styling with optional temporary changes. The style aquarel applies lasts throughout the context manager (with aquarel.Theme:), and switches back to whatever is the global default style outside of it. This allows you to do plot-level temporary changes. You have one plot in your notebook that needs no minor ticks? just with theme.set_ticks(): for this plot only.
  2. Simplified templating: matplotlib stylesheets have a lot of redundant keys for most applications. For example, you rarely want to have different colors for both axes; while possible with a stylefile, its cumbersome to change all the different keys to achieve a uniform look. aquarel simplifies this with e.x. a single set_color(ticks="#eee") call, which changes all related and relevant keys for ticks. Note that this simplifies the API, but does not restrict capabilities: the set_overrides method accepts every possible stylefile key if you want to access low-level styling.
  3. Transforms: some style elements, like trimmed axes, are not achievable with stylesheets alone (see README for more informations). aquarel defines a few of these transforms (and hopefully many more in the future), and makes them persistable and shareable through aquarel themes. Instead of having to apply a seaborn despine after every plot, you can have a global style that specifies a trim, and have consistent styling throughout with minimal code repitition.

@lgienapp lgienapp added documentation Improvements or additions to documentation question Further information is requested labels Aug 23, 2022
@lgienapp
Copy link
Owner

lgienapp commented Aug 23, 2022

Good question by the way; I'll include it in the planned FAQ section in the README (see #5). I'll close this issue in favor of the existing one. Feel free to comment further though.

@lgienapp lgienapp mentioned this issue Aug 23, 2022
2 tasks
@mazzma12
Copy link
Author

Thank you for these details, it is really clear, I like the fact it is a wrapper and not a drop-in replacement or alternative. I like the JSON format better also. Would you have an example of code to convert a stylesheet to the JSON format and conversely?

@lgienapp
Copy link
Owner

There currently is no automatic way to convert an existing stylesheet to aquarel JSON, but two alternatives:

  • drop the existing stylesheet into set_overrides; however, this will not convert to "proper" JSON, but just save the key-values of the stylesheet in the theme file
  • the manual way; i.e. have a look at the aquarel.Theme source code here: https://github.com/lgienapp/aquarel/blob/main/aquarel/theme.py#L98 – you can "reconstruct" which aquarel JSON keys correspond to which matplotlib rcparam keys and go from there to construct a new theme

Given the mapping is more or less reversible this could be automated, but it wouldnt be high on my priority list right now. But if you have time to figure it out, feel free to open a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants