我有一个绘图,其中显示了3个不同的线型图。因此,我明确指定图例显示3种颜色,每个绘图一种。下面是一个玩具的例子:
import matplotlib.pyplot as plt
for i in range(1,20):
if i%3==0 and i%9!=0:
plt.plot(range(1,20),[i+3 for i in range(1,20)], c='b')
elif i%9==0:
plt.plot(range(1,20),[i+9 for i in range(1,20)], c='r')
else:
plt.plot(range(1,20),range(1,20), c='g')
plt.legend(['Multiples of 3 only', 'Multiples of 9', 'All the rest'])
plt.show()
但是图例没有正确显示颜色。为什么会这样?怎么解决?你知道吗
我尝试了Rex5的答案;它在这个玩具示例中起作用,但在我的实际情节(下面)中,由于某种原因,它仍然产生了错误的传说。你知道吗
相反,正如Rex5提供的link中所建议的那样,以下解决方案有效(在玩具示例和我的实际情节中),而且也更简单:
已解决:
请参阅this链接中提供的
doc
链接,这将有助于解释答案。你知道吗相关问题 更多 >
编程相关推荐