Skip to content
Snippets Groups Projects

- major changes in feedback

Merged Hafiz Emin Kosar requested to merge development into master
9 files
+ 531
193
Compare changes
  • Side-by-side
  • Inline
Files
9
%% Cell type:markdown id: tags:
# RWTH Colors
# Colors
When using `rwth_nb.plots.colors`, the RWTH [Corporate Design](http://www.rwth-aachen.de/cms/root/Die-RWTH/Einrichtungen/Verwaltung/Stabsstellen/Marketing/~eqbm/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:
%% Cell type:code id: tags:
``` python
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)
```
%% Cell type:markdown id: tags:
When plotting, colors are cycled through for each graph by following order:
> *blue, orange, green, red, purple, bordeaux, violet, black-50, maigrun, turquoise*
%% Cell type:code id: tags:
``` python
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();
```
%% Cell type:markdown id: tags:
For custom coloring, use as below.
%% Cell type:code id: tags:
``` python
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');
```
%% Cell type:markdown id: tags:
This code is licensed under the [MIT license](https://opensource.org/licenses/MIT).
Loading