Skip to content
Snippets Groups Projects
Commit 2e21e7a8 authored by Tobias Hangleiter's avatar Tobias Hangleiter
Browse files

Add matplotlib cyclers with official RWTH colors

parent 4fc91507
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,9 @@ If you have already downloaded/cloned the package yourself you can use `python s ...@@ -17,6 +17,9 @@ If you have already downloaded/cloned the package yourself you can use `python s
## qutil.plotting ## qutil.plotting
`cycle_plots` helps you cycling through many plots with the arrow keys (there are probably much better functions for this out there) `cycle_plots` helps you cycling through many plots with the arrow keys (there are probably much better functions for this out there)
`plot_2d_dataframe` helps you plot 2d data frames with numeric indices `plot_2d_dataframe` helps you plot 2d data frames with numeric indices
`get_rwth_color_cycle` and the predefined `rwth_color_cycle` are cycler instances with the official RWTH corporate design colors:
![cycler example](./doc/source/_static/cycles.png)
## qutil.matlab ## qutil.matlab
In this module there are functions that are helpful for reading `.mat` files, especially those created with special measure. If you simply want to open a random `.mat` file you can use `hdf5storage.loadmat`. In this module there are functions that are helpful for reading `.mat` files, especially those created with special measure. If you simply want to open a random `.mat` file you can use `hdf5storage.loadmat`.
......
doc/source/_static/cycles.png

134 KiB

"""This module contains some useful plotting functions""" """This module contains some useful plotting functions"""
from collections import OrderedDict
from weakref import WeakValueDictionary from weakref import WeakValueDictionary
from typing import Tuple from typing import Sequence, Tuple
import warnings import warnings
from matplotlib import cycler
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
import pandas as pd import pandas as pd
import numpy as np import numpy as np
__all__ = ["plot_2d_dataframe"] __all__ = ["plot_2d_dataframe", "rwth_color_cycle"]
_color_names = ['blue', 'magenta', 'green', 'orange', 'teal', 'maygreen',
'red', 'purple', 'violet', 'bordeaux', 'petrol', 'yellow']
_color_tuples = [
(0/255, 84/255, 159/255), # blue
(227/255, 0/255, 102/255), # magenta
(87/255, 171/255, 39/255), # green
(246/255, 168/255, 0/255), # orange
(0/255, 152/255, 161/255), # teal
(189/255, 205/255, 0/255), # maygreen
(204/255, 7/255, 30/255), # red
(122/255, 111/255, 172/255), # purple
(97/255, 33/255, 88/255), # violet
(161/255, 16/255, 53/255), # bordeaux
(0/255, 97/255, 101/255), # petrol
(255/255, 237/255, 0/255), # yellow
]
_RWTH_COLORS = OrderedDict(zip(_color_names, _color_tuples))
def _to_corner_coords(index: pd.Index) -> np.ndarray: def _to_corner_coords(index: pd.Index) -> np.ndarray:
...@@ -179,3 +199,45 @@ def cycle_plots(plot_callback, *args, ...@@ -179,3 +199,45 @@ def cycle_plots(plot_callback, *args,
plt.draw_all() plt.draw_all()
return fig, ax return fig, ax
def get_rwth_color_cycle(alpha: float = 1, exclude: Sequence[str] = None):
"""Get the default RWTH color cycle with an alpha channel.
Parameters
----------
alpha: float
The alpha (transparency) value for the color cycle.
exclude: sequence of str
Exclude these colors. See _RWTH_COLORS for all available keys.
Yellow is a good choice to exclude.
Example
-------
>>> cycle_100 = get_rwth_color_cycle(1.)
>>> cycle_50 = get_rwth_color_cycle(.5)
>>> fig, ax = plt.subplots()
>>> x = np.linspace(0, 2*np.pi, 51)
>>> for i, (v100, v50) in enumerate(zip(cycle_100, cycle_50)):
>>> ax.plot(x, np.sin(x) + i / len(cycle_100), lw=2, **v100)
>>> ax.plot(x, -np.sin(x) + i / len(cycle_50), lw=2, **v50)
See Also
--------
https://matplotlib.org/3.3.3/tutorials/intermediate/color_cycle.html
https://matplotlib.org/cycler/
"""
if alpha < 0 or alpha > 1:
raise ValueError('alpha should be in the range [0, 1].')
exclude = exclude or []
return cycler(color=[tup + (alpha,) for name, tup in _RWTH_COLORS.items()
if name not in exclude])
rwth_color_cycle_25 = get_rwth_color_cycle(.25)
rwth_color_cycle_50 = get_rwth_color_cycle(.5)
rwth_color_cycle_75 = get_rwth_color_cycle(.75)
rwth_color_cycle_100 = get_rwth_color_cycle(1)
rwth_color_cycle = rwth_color_cycle_100
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment