Issue
I'm very new to python and I'm experimenting with matplotlib.pyplot. I'm plotting my data using a scatter plot. What I could see from the descriptive statistics all of my columns have 1/4 of missing values. So my question is how does a scatter plot treats missing values? does it ignore them (excluding them from the plot) or it replaces the values by 0? Thanks in advance.
Solution
If there are nan
they are not plotted.
Example:
x = [1,2,3,4,5]
y = [1,np.nan,np.nan, 3, 4]
plt.scatter(x, y)
plt.xlabel('x')
plt.ylabel('y')
plt.show()
On the contrary with y = [1,0,0,3,4]
:
Of course you can replace the nan
with 0
or other values. The 'how' depends the kind of your data. For list:
import math
y = [0 if math.isnan(e) else e for e in y]
Answered By - Joe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.