Hiding All Points Above A Plotted Line In A Scatter Plot
Plotting 2 lists of galaxy equivalent width ratios, Im plotting them against each other then I want to eliminate all points above the line y=(0.61)/(x-0.05)+1.3 so that only points
Solution 1:
I believe the easiest way to do this will be to simply filter the desired points out before plotting, you can do so with
filteredx = list()
filteredy = list()
for ii in range(len(NT)):
if OT[ii] < (0.61) / (NT[ii] - 0.05) + 1.3: #Adjust equation as needed
filteredx.append(NT[ii])
filteredy.append(OT[ii])
plt.scatter(filteredx, filteredy)
For a complete example:
import numpy as np
import matplotlib.pyplot as plt
# Create random data for demonstration
np.random.seed(1)
n = 200
datay = np.random.randn(n)*50
datax = np.random.randn(n)*1.5
x = np.linspace(-5, 5, 1000)
y = (0.61) / (x - 0.05) + 1.3
filteredx = list()
filteredy = list()
plt.scatter(datax, datay, marker='o', color='g', label="All Points")
for ii inrange(n):
if datay[ii] < (0.61) / (datax[ii] - 0.05) + 1.3:
filteredx.append(datax[ii])
filteredy.append(datay[ii])
plt.scatter(filteredx, filteredy, marker='.', color='r', label="After Filtering")
plt.plot(x,y, linewidth=1, linestyle='-')
plt.legend()
plt.show()
To remove the asymptote you can filter for values larger than and less than
x = 0.05
and plot the two groups separately, i.e.
plt.plot(x[x < 0.05], y[x < 0.05], linewidth=1, linestyle='-', color='b')
plt.plot(x[x > 0.05], y[x > 0.05], linewidth=1, linestyle='-', color='b')
You do in this case need to specify the color, otherwise the two regions will have different colors. Additionally, if you need to label the line for the legend, simply give one of the two a label
- if you give one to each region you will end up getting two legend entries.
Post a Comment for "Hiding All Points Above A Plotted Line In A Scatter Plot"