matplotlib错误栏可以设置线型吗? [英] Can matplotlib errorbars have a linestyle set?
本文介绍了matplotlib错误栏可以设置线型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将相同的线型设置为 matplotlib 错误栏而不是数据点线型?
Is is possible to set the same linestyle to matplotlib errorbars than to the datapoints linestyle?
在下面的示例中,绘制了两条线,其中一条线由于 ls='-.' 而用虚线表示.范围.但是,误差条是实线.是否可以修改错误栏的样式/外观以匹配结果行?
In the example below, two lines are plotted, one of them is dashed because of the ls='-.' parameter. However, the errorbar are solid lines. Is is possible to modify the style/look of the errorbars to match the results line?
import matplotlib.pyplot as plt
import numpy as np
x = np.array(range(0,10))
y = np.array(range(0,10))
yerr = np.array(range(1,11)) / 5.0
yerr2 = np.array(range(1,11)) / 4.0
y2 = np.array(range(0,10)) * 1.2
plt.errorbar(x, y, yerr=yerr, lw=8, errorevery=2, ls='-.')
plt.errorbar(x, y2, yerr=yerr2, lw=8, errorevery=3)
plt.show()
推荐答案
这很简单,更改错误栏的线型只需要简单的 .set_linestyle
调用:
It is trivial, changing the linestyle of the errorbars only require a simple .set_linestyle
call:
eb1=plt.errorbar(x, y, yerr=yerr, lw=2, errorevery=2, ls='-.')
eb1[-1][0].set_linestyle('--') #eb1[-1][0] is the LineCollection objects of the errorbar lines
eb2=plt.errorbar(x, y2, yerr=yerr2, lw=2, errorevery=3)
eb2[-1][0].set_linestyle('-.')
这篇关于matplotlib错误栏可以设置线型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文