如何使用Matplotlib强制错误栏最后渲染 [英] How to force errorbars to render last with Matplotlib
问题描述
我正在尝试对一些经验数据进行过度绘制,并在建模数据之上加上误差线.误差线似乎首先被渲染,因此被覆盖(见下文)
I am trying over-plot some empirical data with error bars on top of my modelled data. The error bars seem to be rendering first and are consequently getting over written (see below)
我尝试使用zorder,但仍然得到相同的结果.我正在使用的代码是
I have tried using zorder but I still get the same result. The code I am using is
for i in range(1,len(pf)):
pf[i,:] = av_pf_scale * pf[i,:]
pylab.semilogy(pf[0,0:180],pf[i,0:180],color='0.75')
pylab.semilogy(av_pf[0:180],color='r')
pylab.semilogy(av_mie[0:180],color='g', linestyle='-')
pylab.draw()
f = pylab.errorbar(ang,data[j],
yerr = delta_data[j],
fmt = 'o',
markersize = 3,
color = 'b',
zorder = 300,
antialiased = True)
如果有人能告诉我如何使错误栏显示在顶部,我将不胜感激.
I would appreciate if anyone can tell me how to make the errorbars render on top.
推荐答案
这似乎是matplotlib
中的错误,其中errorbar
的zorder
参数未正确传递到错误的垂直线部分酒吧.
This looks like it is a bug in matplotlib
where the zorder
argument of the errorbar
is not correctly passed to the vertical lines part of error bars.
重复您的问题:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = plt.gca()
[ax.plot(rand(50),color='0.75') for j in range(122)];
ax.errorbar(range(50),rand(50),yerr=.3*rand(50))
plt.draw()
Hacky解决方法:
Hacky work around:
fig = plt.figure()
ax = plt.gca()
[ax.plot(rand(50),color='0.75',zorder=-32) for j in range(122)];
ax.errorbar(range(50),rand(50),yerr=.3*rand(50))
plt.draw()
作为问题报告给matploblib https://github.com/matplotlib/matplotlib/issues/1622 (现已打补丁并关闭)
report as an issue to matploblib https://github.com/matplotlib/matplotlib/issues/1622 (now patched and closed)
这篇关于如何使用Matplotlib强制错误栏最后渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!