如何在matplotlib中设置误差线帽的线宽? [英] How to set the line width of error bar caps, in matplotlib?
问题描述
如何改变 Matplotlib 中误差线大写的线宽?
How can the line width of the error bar caps in Matplotlib be changed?
我尝试了以下代码:
(_, caplines, _) = matplotlib.pyplot.errorbar(
data['distance'], data['energy'], yerr=data['energy sigma'],
capsize=10, elinewidth=3)
for capline in caplines:
capline.set_linewidth(10)
capline.set_color('red')
pp.draw()
不幸的是,这会更新大写的颜色,但不会更新大写的线宽!
Unfortunately, this updates the color of the caps, but does not update the line width of the caps!
产生的效果类似于下图中的fat error bar lines/thin caps":
The resulting effect is similar to the "fat error bar lines / thin caps" in the following image:
在这种情况下,最好有胖"的酒吧帽;在 Matplotlib 中如何做到这一点?使用 plot()
一个接一个地手动"绘制条形图即可,但是最好使用一种更简单的替代方法.
It would be nice to have "fat" bar caps, in the case; how can this be done, in Matplotlib? Drawing the bar caps "manually", one by one with plot()
would work, but a simpler alternative would be best.
推荐答案
这是基于@joaquin 的回答,但更简洁一些(如果你只是想要没有特殊样式的普通错误大写):
This is based on @joaquin's answer, but a little more concise (if you just want plain error caps with no special styling):
distance = [1,3,7,9]
energy = [10,20,30,40]
sigma = [1,3,2,5]
plt.errorbar(distance,
energy,
sigma,
capsize=5,
elinewidth=2,
markeredgewidth=2)
这篇关于如何在matplotlib中设置误差线帽的线宽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!