gpt4 book ai didi

python - 更改图形线条颜色

转载 作者:太空宇宙 更新时间:2023-11-04 05:57:53 28 4
gpt4 key购买 nike

我正在尝试使用 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)

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

最佳答案

使用 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

关于python - 更改图形线条颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26762980/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com