Package: aquarel
Aquarel 🎨Aquarel is a lightweight templating engine and wrapper around Matplotlibs'rcparamsto make styling plots simple.
Aquarel templates can be defined programmatically and be serialized and shared in a JSON format.Full documentation is available ataquarel.readthedocs.io.InstallationInstall via pip:python-mpipinstallaquarelUsageApplying a styleStyles can be either applied globallyfromaquarelimportload_themetheme=load_theme("arctic_light")theme.apply()# ... plotting code heretheme.apply_transforms()...or with a context manager:fromaquarelimportload_themewithload_theme("arctic_light"):figure=# ... plotting code hereTransformsThemes may specifytransforms. Transforms are functions applied on the finished plot to achieve aesthetics that are not possibly by means ofrcparamsonly.
For example, to trim the axes, one could apply thetrimtransform:fromaquarelimportload_themewithload_theme("arctic_light").set_transforms(trim=True):figure=# ... plotting code here# plt.show() or savefig() have to be called outside the context manager to have the transforms correctly applied.figure.savefig()However, there is one important thing to keep in mind: since transforms require the matplotlib figure/axes object to be present and finished, they have to be appliedafterthe plotting code.
When using a theme with a context manager, this is automatically done in the__exit__call. If global usage is desired,Theme.apply_transforms()has to be called after every figure.
This also means that calls that make use of the finished figure, i.e.plt.showorplt.savefighave to commence after transform application, sooutsidethe context manager.Customization & Theme CreationBesides loading a predefined theme, you can create a new themefromaquarelimportThemetheme=(Theme(name="demo",description="A demo theme.").set_grid(draw=True,width=0.5).set_font(family="monospace").set_color(grid_color="blue"))...modify an existing onefromaquarelimportload_themetheme=(load_theme("arctic_light").set_grid(width=2))...and write and load your custom styles to and from disk:fromaquarelimportThemetheme=Theme.from_file("custom.json")theme.save("custom.json")If the simplified API of aquarel is not sufficient for your use-case, you can also directly modify the underlyingrcparamswith overrides:fromaquarelimportload_themetheme=load_theme("arctic_light").set_overrides({"ytick.minor.visible":False,"xtick.minor.visible":True})Themesaquarel ships with several pre-defined themes that are designed to showcase its templating capabilities.
Add your own with a pull request!NameDescriptionPreviewarctic_darkFrosty dark theme based on thenordcolor schemearctic_lightFrosty dark theme based on thenordcolor schemeboxy_darkDark theme with enclosing box and gridboxy_lightLight theme with enclosing box and gridgruvbox_darkDark theme with pastelretro groove colorsgruvbox_lightLight theme with pastelretro groove colorsminimal_darkDark theme with minimal visual elementsminimal_lightLight theme with minimal visual elementsscientificSpace-efficient and color-blind friendly theme for printing on paperumbra_darkBalanced dark theme based on thepenumbracolor schemeumbra_lightBalanced light theme based on thepenumbracolor schemeFAQHow is this different from matplotlib style sheets?aquarelis a wrapper around the stylesheets, so everything you can do with stylesheets can be achieved withaquarel. However there are some notable shortcomings of stylesheets thataquareladresses: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, ...).aquareltakes a different approach here and aims to provide per-plot styling with optional temporary changes. The styleaquarelapplies 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? justwith theme.set_ticks():for this plot only.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.aquarelsimplifies this with e.x. a singleset_color(ticks="#eee")call, which changes all related and relevant keys for ticks. Note that this simplifies the API, but does not restrict capabilities: theset_overridesmethod accepts every possible stylefile key if you want to access low-level styling.Transforms: some style elements, like trimmed axes, are not achievable with stylesheets alone (see README for more informations).aquareldefines 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 repetition.