Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 396
Caustic Avatar asked Dec 22 '12 14:12

Caustic


People also ask

What is Matplotlib Errorbar?

Matplotlib line plots and bar charts can include error bars. Error bars are useful to problem solvers because error bars show the confidence or precision in a set of measurements or calculated values.

How do I get Matplotlib error bars?

By using the plt. errorbar() method we plot the error bars and pass the argument xerr to plot error on the x values in the scatter plot. In the above example, we import matplotlib. pyplot library and define the data point on the x-axis and y-axis.

How do you plot asymmetric error bars?

Asymmetric error bars can be computed from raw data simply by selecting different computations for the upper and lower error bars. However, if you have your error bar data in multiple columns, you will need to select the “Asymmetric Error Bar Columns” option.


1 Answers

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)

like image 184
tacaswell Avatar answered Sep 28 '22 21:09

tacaswell