2
有沒有什麼辦法讓我在一個matplotlib PathPatch上有多種顏色?我有以下代碼,例如,我想給每個「段」自己的顏色(即從0,0到0,1的段可以是紅色,從0,1到2,2可以是橙色,從4,3至5,3可以是黃色的)。我想做到這一點,而不使用集合,只是使用PathPatch多種顏色的一個PathPatch
import matplotlib as mpl
import matplotlib.pyplot as plt
fig2, ax2 = plt.subplots()
verts = [(0,0), (0,1), (2,2), (4,3), (5,3)]
codes = [1,2,2,1,2]
pat = mpl.patches.PathPatch(mpl.patches.Path(verts, codes), fill=False, linewidth=2, edgecolor="red")
ax2.add_patch(pat)
ax2.set_xlim(-2, 6)
ax2.set_ylim(-2, 6)
如果您只有strait部分,'LineCollection'也可能有幫助。 – tacaswell