Reputation: 1191
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)
Upvotes: 6
Views: 23194
Reputation: 18547
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).
Upvotes: 11