简体   繁体   中英

Scatter Plot and missing values

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.

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]

I am facing this exact same issue. I am using a csv file with the missing rows dropped to make my scatter plot. I have also use matplotlib yet I am getting not output despite having the R value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM