看来这成功了:
from pandas import DataFrame
import matplotlib.pyplot as plt
if __name__ == '__main__':
lower_bound = [0, 1, 2, 3]
value = [1, 2, 3, 4]
upper_bound = [2, 3, 4, 5]
d = {'Lower bound': lower_bound, 'Value': value, 'Upper bound': upper_bound}
df = DataFrame(data=d)
ax = df.plot(color=["Blue", "Blue", "Red"])
lines, labels = ax.get_legend_handles_labels()
ax.legend([lines[0], lines[2]], ["Bounds", "Value"])
plt.show()
我猜测为什么颜色是按这个顺序排列的:pandas 必须在绘制之前对列名称进行排序。你会认为它会是
colors = ["Blue", "Red", "Blue"]
但请注意,“下限”、“上限”和“值”是键的字母顺序。
NOTE:这是 anaconda 2.7,Python 3 的行为可能有所不同。