Reputation: 670
I want to make a plot of lines with opaque scatter markers superimposed on them at certain points. But the lines keep shining through markers, even with alpha=1
:
import matplotlib.pyplot as plt
plt.close('all')
plt.plot([0, 2], [0, 0], color='black')
plt.scatter([1], [0], color='red', alpha=1)
plt.savefig('/tmp/foo.png')
How to make the red marker really opaque, i.e. make the black line completely invisible beneath it?
Upvotes: 2
Views: 839
Reputation: 80509
Your problem is the z-order of the elements. Default, lines will be drawn on top of markers. Use plt.scatter(..., zorder=3)
to force the markers on top.
import matplotlib.pyplot as plt
plt.plot([0, 2], [0, 0], color='black')
plt.scatter([1], [0], color='red', alpha=1, zorder=3)
plt.show()
Upvotes: 4