我想在matplotlib中制作复杂的图例。我编写了以下代码
import matplotlib.pylab as plt
import numpy as np
N = 25
y = np.random.randn(N)
x = np.arange(N)
y2 = np.random.randn(25)
# serie A
p1a, = plt.plot(x, y, "ro", ms=10, mfc="r", mew=2, mec="r")
p1b, = plt.plot(x[:5], y[:5] , "w+", ms=10, mec="w", mew=2)
p1c, = plt.plot(x[5:10], y[5:10], "w*", ms=10, mec="w", mew=2)
# serie B
p2a, = plt.plot(x, y2, "bo", ms=10, mfc="b", mew=2, mec="b")
p2b, = plt.plot(x[15:20], y2[15:20] , "w+", ms=10, mec="w", mew=2)
p2c, = plt.plot(x[10:15], y2[10:15], "w*", ms=10, mec="w", mew=2)
plt.legend([p1a, p2a, (p1a, p1b), (p2a,p2b), (p1a, p1c), (p2a,p2c)],
["No prop", "No prop", "Prop +", "Prop +", "Prop *", "Prop *"], ncol=3, numpoints=1)
plt.show()
但我希望像这样绘制复杂的图例:
我还尝试使用table
函数创建图例,但是无法将修补程序对象放置到单元格的正确位置。
tablelegend
函数 在这个答案中,它可能对此有用。 - Zaus