注意
跳到結尾下載完整範例程式碼。
陰影樣式參考#
陰影可以新增到 Matplotlib 中的大多數多邊形,包括 bar
、fill_between
、contourf
,以及 Polygon
的子項。目前 PS、PDF、SVG、macosx 和 Agg 後端支援它們。WX 和 Cairo 後端目前不支援陰影。
另請參閱 等高線填滿陰影,以取得使用 contourf
的範例,以及 陰影演示,以取得更多使用範例。
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
fig, axs = plt.subplots(2, 5, layout='constrained', figsize=(6.4, 3.2))
hatches = ['/', '\\', '|', '-', '+', 'x', 'o', 'O', '.', '*']
def hatches_plot(ax, h):
ax.add_patch(Rectangle((0, 0), 2, 2, fill=False, hatch=h))
ax.text(1, -0.5, f"' {h} '", size=15, ha="center")
ax.axis('equal')
ax.axis('off')
for ax, h in zip(axs.flat, hatches):
hatches_plot(ax, h)

可以重複陰影模式以增加密度。

可以組合陰影模式以建立其他模式。

參考資料
此範例中顯示下列函式、方法、類別和模組的使用
指令碼總執行時間: (0 分鐘 1.841 秒)