技巧#

import matplotlib.pyplot as plt
import numpy as np

Zoom-in#

step = 0.1
x = np.arange(0, 10 + step, step)
y = x**2
_, ax = plt.subplots(figsize=[10, 8])
ax.plot(x, y)

axins = ax.inset_axes([0.1, 0.5, 0.4, 0.4])
axins.plot(x[:10], y[:10])

ax.indicate_inset_zoom(axins, lw=3)

axins.set_xticklabels("")
axins.set_yticklabels("")
plt.show()
../_images/65dd41cfe5f7fdd923aec6cb1edf6ca3c8eda5bc62d3ba48105939c644f5294a.png

Table#

_, ax = plt.subplots(figsize=(10, 6))

x = np.random.rand(5, 8) * 0.7

ax.plot(x.mean(axis=0), "-o", label="average per column")
ax.set(xticks=[])
ax.table(
    cellText=[[f"{xxx}%1.2f" for xxx in xx] for xx in x],
    cellColours=plt.cm.GnBu(x),
    fontsize="large",
    loc="bottom",
)
plt.show()
../_images/15f075d9c9323791fe17f75d81800278abc7c526b0df00affb675bcba0856be0.png

Broken Bars#

_, ax = plt.subplots(figsize=(10, 6))

x1 = [(5, 5), (20, 5), (20, 7)]
y1 = (2, 1)
ax.broken_barh(x1, y1, facecolors="green")

x2 = [(6, 2), (17, 5), (50, 2)]
y2 = (15, 1)
ax.broken_barh(x2, y2, facecolors="orange")

x3 = [(5, 2), (28, 5), (40, 2)]
y3 = (30, 1)
ax.broken_barh(x3, y3, facecolors="red")

ax.set(xlabel="Sales", ylabel="Days of the Month")
plt.show()
../_images/702ebf97db0c53ee8dc78b4810bd6eceb15558d7a415a486bf2bf2902bcb5e7a.png

Transform#