首页 > 解决方案 > 单图多行传递一组颜色?

问题描述

用一个plot命令绘制两条线应该不容易?

import matplotlib.pyplot as plt
plt.plot([[1,2],[5,6]], c=['k','g'])

ValueError: Invalid RGBA argument

我只需要两条线,一条是黑色的,另一条是绿色的。这里发生了什么?

标签: pythonmatplotlib

解决方案


您需要有 2 条线,而不是 2 个点来绘制 2 条线。

import matplotlib.pyplot as plt

plt.plot(x1, y1,  c = 'k')
plt.plot(x2, y2,  c = 'g') #x1, y1, x2, y2 should be multiple points

推荐阅读