Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
538 views
in Technique[技术] by (71.8m points)

python - 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)

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.

Mulitplot

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

replicates your problem :

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()

error bar fail 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()

error bar hack

report as an issue to matploblib https://github.com/matplotlib/matplotlib/issues/1622 (now patched and closed)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...