改变图线颜色

时间:2014-11-05 17:06:14

标签: python python-2.7 matplotlib

我正在尝试使用OS X创建一个图形,这就是我所拥有的:

import matplotlib.pyplot as plt
import numpy as np
import scipy as sp
x_series = [22,25,28,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100]
y_series = [113800,101800,87000,78700,61800,49900,39700,32800,25900,21500,17500,14300,11900,9800,8300,6900,5600,4900]
plt.title("Temperature variation of resistance")
plt.xlabel("Temperature(degrees celcius)")
plt.ylabel("Resistance(ohms)")
y_sig = ([100.,100.,100.,100.,100.,100.,100.,100.,100.,100.,100.,100.,100.,100.,100.,100.,100.,100.])
plt.errorbar(x_series,y_series,y_sig)

我想要做的就是更改图表线颜色,与错误栏进行对比。任何帮助,将不胜感激;到目前为止我在网上阅读的任何内容都没有用。

1 个答案:

答案 0 :(得分:1)

使用plt.errorbar时,线条的颜色和误差线可分别由关键字参数colorecolor控制。

以下修改后的代码会将线条颜色设置为黑色,将错误颜色设置为红色。

import matplotlib.pyplot as plt
import numpy as np
import scipy as sp

x_series = [22,25,28,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100]
y_series = [113800,101800,87000,78700,61800,49900,39700,32800,25900,21500,17500,14300,11900,9800,8300,6900,5600,4900]

plt.title("Temperature variation of resistance")
plt.xlabel("Temperature(degrees celcius)")
plt.ylabel("Resistance(ohms)")

y_sig = ([100.,100.,100.,100.,100.,100.,100.,100.,100.,100.,100.,100.,100.,100.,100.,100.,100.,100.])

plt.errorbar(x_series,y_series,y_sig, color='black', ecolor='red')

plt.show()

Example plot