RWTH ColorsΒΆ

When using rwth_nb.plots.colors, the RWTH Corporate Design color scheme is stored in a dictionary called rwth_colors. When loading rwth_nb.plots.mpl_decorations, the RWTH colors are propagated to Matplotlib as well. The following colors may be used:

[1]:
import matplotlib.pyplot as plt
from rwth_nb.plots import colors

# adapted from https://matplotlib.org/2.0.0/examples/color/named_colors.html
colors = colors.rwth_colors;
fontsize = 12
ncols = 5; nrows = len(colors.keys()) // ncols + 1;

fig, ax = plt.subplots(figsize=(12, 6))
X, Y = fig.get_dpi() * fig.get_size_inches() # Get height and width
w = X / ncols; h = Y / nrows

for i, name in enumerate(colors.keys()):
    col = i % ncols
    row = i // ncols
    y = Y - (row * h) - h

    xi_line = w * (col + 0.05); xf_line = w * (col + 0.25); xi_text = w * (col + 0.3)
    ax.text(xi_text, y, name, fontsize=fontsize, horizontalalignment='left', verticalalignment='center')
    ax.hlines(y + h * 0.1, xi_line, xf_line, color=colors[name], linewidth=(h * 0.6))

ax.set_xlim(0, X); ax.set_ylim(0, Y); ax.set_axis_off();
fig.subplots_adjust(left=0, right=1, top=1, bottom=0, hspace=0, wspace=0)
/usr/local/lib/python3.8/site-packages/traitlets/traitlets.py:3030: FutureWarning: --rc={'figure.dpi': 96} for dict-traits is deprecated in traitlets 5.0. You can pass --rc <key=value> ... multiple times to add items to a dict.
  warn(
../_images/examples_RWTH_Colors_1_1.svg
When plotting, colors are cycled through for each graph by following order:
> blue, orange, green, red, purple, bordeaux, violet, black-50, maigrun, turquoise
[2]:
import numpy as np
import rwth_nb.plots.mpl_decorations as rwth_plt

x = np.linspace(-2, 2, 501)

fig, ax = plt.subplots()
ax.set_ylim(-2, 2)
rwth_plt.axis(ax); rwth_plt.grid(ax)

for n in range(10):
    ax.plot(x, x**n, label=r'$x^{}$'.format(n))

ax.legend();
[2]:
<matplotlib.legend.Legend at 0x7f2f7c590820>
../_images/examples_RWTH_Colors_3_1.svg

For custom coloring, use as below.

[3]:
import numpy as np
import rwth_nb.plots.mpl_decorations as rwth_plt

x = np.linspace(-4,4);

fig,ax = plt.subplots();
ax.plot(x, x**2, 'rwth:blue');
ax.plot(x, x**2 + np.random.randn(len(x)), '.', color='rwth:green');
[3]:
[<matplotlib.lines.Line2D at 0x7f2f7c394fd0>]
../_images/examples_RWTH_Colors_5_1.svg

This code is licensed under the MIT license.