2

I need to plot the following error bars for my project. And I control the size of the marker using matplotlib.scatter as follows:

import matplotlib.pyplot as plt
import numpy as np
x=[1,2,3]
y=[1,2,3]
yerr=[2,3,1]
fig,(ax1)=plt.subplots(1,1)
ax1.errorbar(x,y,yerr=yerr, linestyle='-', capsize=3, ecolor='lightblue', elinewidth=2)
ax1.scatter(x, y, s=[20]*len(x), marker='o', color='#1f77b4')
plt.show()

The results are like the following:

enter image description here

The markers are plotted under the error bar, which is not nice. Any solutions?

f. c.
  • 1,095
  • 11
  • 26
  • I'm not sure what you're asking. Which marker are you looking at? The dot or the top of the bar? – Mad Physicist Jan 13 '23 at 15:28
  • Does this answer your question? [Specifying the order of matplotlib layers](https://stackoverflow.com/questions/37246941/specifying-the-order-of-matplotlib-layers) – Jody Klymak Jan 13 '23 at 22:44

1 Answers1

2

Try using zorder:

ax1.scatter(x, y, s=[20]*len(x), marker='o', color='#1f77b4', zorder=10)
Scott Boston
  • 147,308
  • 15
  • 139
  • 187