Colors, linestyles, and markers

Named colors, hex, fmt strings, and marker size.

Color is a keyword, a C0 cycle index, or a hex string. Markers and linestyles are separate.

Goal

Use named colors, the default cycle, hex, and a few markers.

Named and hex

x = np.linspace(0, 4, 40)
fig, ax = plt.subplots()
ax.plot(x, x, color="steelblue", label="named")
ax.plot(x, x + 1, color="#c45c26", label="hex")
ax.plot(x, x + 2, color="C2", label="cycle C2")
ax.legend()
ax.set_title("color=")
plt.show()

C0, C1, … follow the current style’s color cycle.

Markers

x = np.linspace(0, 4, 8)
fig, ax = plt.subplots()
for mark, yoff in zip(["o", "s", "^", "D"], range(4)):
    ax.plot(x, x + yoff, marker=mark, label=mark)
ax.legend(title="marker")
ax.set_title("Markers")
plt.show()

Linewidth

x = np.linspace(0, 2 * np.pi, 80)
fig, ax = plt.subplots()
ax.plot(x, np.sin(x), linewidth=1, label="1")
ax.plot(x, np.sin(x) - 0.3, linewidth=2.5, label="2.5")
ax.legend(title="lw")
plt.show()
Tip

Color-blind-safe charts use linestyle or marker, not color alone. Dashed vs solid still reads in grey.