Ignoring plotting data points of certain value

百般思念 提交于 2019-12-23 17:38:06

问题


I have a plot shown below and I am trying to figure out a way to ignore plotting points that have x value = 0.0. Basically, I want my plot to not include those 3 points you see in the top left corner.

y = np.array([4.7, 6.6, 6.4, 6.8, 6.2, 7.2, 6.1, 5.9, 6.4, 6.6])
x = np.array([0.405,0.0,1.254,1.096,1.128,0.0,0.828,1.083,1.309,0.0])

plt.scatter(x, y)


回答1:


There are two ways, depending on whether you want to actually stop plotting them, or just stop showing them.

The first is to just set the limits of the x-axis so that those points aren't visible. At the end of your script, you can do

plt.xlim(left=0.3)

The other method is to actually cut those points out of the data before plotting. To do this:

x = x[x > 0.0]
y = y[x > 0.0]

plt.scatter(x, y)

Note that in both cases, we're indexing by x > 0.0 to cut out only the points for which the x value is 0 (the y values could be anything).



来源:https://stackoverflow.com/questions/24807991/ignoring-plotting-data-points-of-certain-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!