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