Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignoring plotting data points of certain value

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)

enter image description here

like image 940
user1821176 Avatar asked Jul 17 '14 15:07

user1821176


People also ask

What is plotting in coding?

A plot is a graphical technique for representing a data set, usually as a graph showing the relationship between two or more variables. The plot can be drawn by hand or by a computer. In the past, sometimes mechanical or electronic plotters were used.


1 Answers

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).

like image 59
tbekolay Avatar answered Sep 25 '22 03:09

tbekolay