Search code examples
pythonmatplotliberrorbar

Matplotlib, draw on top


I am drawing an errorbar plot of some data points, and alongside these points, I want to draw the average in-between two values a line, I also want the line to be drawn on top of the errorbar.

In my code, I write the pyplot.errorbar(...) to draw the data points first, and then pyplot.plot(...) to draw the lines, and the result is that the errorbar is plotted on top of the lines, such that the line is hardly visible:

The orange line is hard to see

I have no idea as to how to draw the line on top, this is likely really easy to do, but I do not know how to do so.


Solution

  • This is generally controlled using the zorder https://matplotlib.org/3.1.1/gallery/misc/zorder_demo.html

    pyplot.plot([0,1], [0,1], linewidth=10)
    pyplot.errorbar([0.5], [0.5], 0.3, 0.3, linewidth=20, zorder=-100)
    

    enter image description here

    pyplot.plot([0,1], [0,1], linewidth=10)
    pyplot.errorbar([0.5], [0.5], 0.3, 0.3, linewidth=20, zorder=100)
    

    enter image description here