Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting line graph over scatter graph

I am aware of how to plot a line graph on top of scatter plot of the same data but is there a way to bring the line graph forward so it sits on top of the markers rather than behind?

Example code:

import numpy as np

x=np.array([1,2,3,4,5])
y=np.array([1,2,3,4,5])

plt.errorbar(x,y,xerr=0.1,yerr=0.1, fmt="x",markersize=5, color = "orange")
plt.plot(x,y)

This code outputs a scatter graph with a line graph behind it. When you increase the number of data points it becomes harder to see the line behind them all. Other than decreasing the marker size can I bring the line on top of all the points?

like image 632
Oliver Moore Avatar asked Dec 21 '25 21:12

Oliver Moore


1 Answers

I think you are intending to draw things at different levels of z-order on the screen. This is done like such:

plt.plot(x,y, zorder=10)

Note 10 is arbitrarily large and this will likely plot on top of your legend too, so you may need to adjust it!

like image 165
Reedinationer Avatar answered Dec 23 '25 10:12

Reedinationer