-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Expand file tree
/
Copy pathcolor_cycle_default.py
More file actions
54 lines (44 loc) · 1.32 KB
/
color_cycle_default.py
File metadata and controls
54 lines (44 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
====================================
Colors in the default property cycle
====================================
Display the colors from the default prop_cycle, which is obtained from the
:ref:`rc parameters<customizing>`.
"""
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import TABLEAU_COLORS, same_color
def f(x, a):
"""A nice sigmoid-like parametrized curve, ending approximately at *a*."""
return 0.85 * a * (1 / (1 + np.exp(-x)) + 0.2)
fig, ax = plt.subplots()
ax.axis('off')
ax.set_title("Colors in the default property cycle")
prop_cycle = plt.rcParams['axes.prop_cycle']
colors = prop_cycle.by_key()['color']
x = np.linspace(-4, 4, 200)
for i, (color, color_name) in enumerate(zip(colors, TABLEAU_COLORS)):
assert same_color(color, color_name)
pos = 4.5 - i
ax.plot(x, f(x, pos))
ax.text(4.2, pos, f"'C{i}': '{color_name}'", color=color, va="center")
ax.bar(9, 1, width=1.5, bottom=pos-0.5)
plt.show()
# %%
#
# .. admonition:: References
#
# The use of the following functions, methods, classes and modules is shown
# in this example:
#
# - `matplotlib.axes.Axes.axis`
# - `matplotlib.axes.Axes.text`
# - `matplotlib.colors.same_color`
# - `cycler.Cycler`
#
# .. tags::
#
# styling: color
# purpose: reference
# plot-type: line
# level: beginner