Creating color-cycles

Creating color-cycles#

[1]:
import matplotlib.pyplot as plt
import numpy as np

from tueplots import cycler
from tueplots.constants import markers
from tueplots.constants.color import palettes

# Increase the resolution of all the plots below
plt.rcParams.update({"figure.dpi": 150})

cycler objects define the default color choices in matplotlib (e.g., blue-orange-red-…). Like most other settings provided in tueplots, the outputs of cycler are directly compatible with plt.rcParams.update() (which is different to the cycler object in matplotlib in that it wraps them into a dictionary).

We can control the cyclers through the constants in tueplots.constants. To see this, let us generate some lines to be plotted. (Setup taken from https://matplotlib.org/stable/tutorials/intermediate/color_cycle.html).

[2]:
x = np.linspace(0, np.pi, 20)
offsets = np.linspace(0, 2 * np.pi, 8, endpoint=False)
yy = [np.sin(x + phi) for phi in offsets]

The following are the default colors:

[3]:
for y in yy:
    plt.plot(x, y, linewidth=3)
plt.show()
../_images/example_notebooks_color-cycles_5_0.png

Through the dictionaries provided by tueplots, we can change the default color behaviour as follows.

[4]:
plt.rcParams.update(cycler.cycler(color=palettes.tue_plot))
for y in yy:
    plt.plot(x, y, linewidth=3)
plt.show()
../_images/example_notebooks_color-cycles_7_0.png
[6]:
plt.rcParams.update(cycler.cycler(color=palettes.paultol_muted))
for y in yy:
    plt.plot(x, y, linewidth=3)
plt.show()
../_images/example_notebooks_color-cycles_8_0.png
[7]:
plt.rcParams.update(cycler.cycler(color=palettes.paultol_high_contrast))
for y in yy:
    plt.plot(x, y, linewidth=3)
plt.show()
../_images/example_notebooks_color-cycles_9_0.png
[8]:
plt.rcParams.update(cycler.cycler(color=palettes.pn))
for y in yy:
    plt.plot(x, y, linewidth=3)
plt.show()
../_images/example_notebooks_color-cycles_10_0.png

We can also cycle linestyles and markers.

[9]:
plt.rcParams.update(cycler.cycler(color=palettes.pn[:3], marker=markers.o_sized[:3]))
for y in yy:
    plt.plot(x, y, linewidth=3, markersize=10)
plt.show()
../_images/example_notebooks_color-cycles_12_0.png
[10]:
plt.rcParams.update(
    cycler.cycler(color=palettes.paultol_vibrant[:3], marker=markers.x_like_bold[:3])
)
for y in yy:
    plt.plot(x, y, linewidth=3, markersize=10)
plt.show()
../_images/example_notebooks_color-cycles_13_0.png
[11]:
plt.rcParams.update(
    cycler.cycler(
        color=palettes.paultol_medium_contrast[:3], marker=markers.x_like_bold[:3]
    )
)
for y in yy:
    plt.plot(x, y, linewidth=3, markersize=10)
plt.show()
../_images/example_notebooks_color-cycles_14_0.png
[ ]: