How to force errorbars to render last with Matplotlib

后端 未结 2 1565
伪装坚强ぢ
伪装坚强ぢ 2020-12-14 19:57

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

相关标签:
2条回答
  • 2020-12-14 20:50

    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)

    0 讨论(0)
  • 2020-12-14 21:00

    This is a known bug in matplotlib. Link to github issue

    Hacky solution: Add the argument zorder=3 when you call plt.errorbar, like plt.errorbar(..., zorder=3)

    0 讨论(0)
提交回复
热议问题