技巧#

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/f9370620aaaf7e3f9f4463428e395b6f6e8127a9ea2bc3761f3e8d29707f46d4.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/7247862ad9e97f999d308fc64ecbc649e09130c2b8d41b57e556458437c2fe49.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/b011a6076fda54f022281f0d93edce4e8bfcc04c8b9a1b854bc31b163a1c8468.png

Transform#