Ma Y
Ma Y

Reputation: 706

Using IF statement for separating negative and positive values read from text file

In the following code I contains positive and negative values. I want to use just positive ones or negative ones. I defined an IF but it does not work and again in the final plot I have all negative and positive values. Any help, please?

n, t, I = np.genfromtxt('...Desktop/uf/Inu3.txt',unpack=True)
if (I>0).any():
        df=pd.DataFrame(data={'A':n,'B':t,'C':I})
        points = plt.scatter(df.A, df.B, c=df.C,cmap="jet", lw=0)#, norm=matplotlib.colors.LogNorm())
        plt.yscale('log')
        plt.xscale('log')

        plt.xlabel(r'$n_{g}$',fontsize=20)
        plt.ylabel(r'$T_{g}$',fontsize=20)
        cb = plt.colorbar()
        cb.ax.tick_params(labelsize=10)
        cb.set_label(label=r'$I_{\nu}[Jy/sr]$', size='15')
else:
    pass

Upvotes: 0

Views: 84

Answers (1)

shayelk
shayelk

Reputation: 1656

if (I>0).any()

Basically asks if there is any positive number in I. so if at least one positive value exists, you're using all the values in it.

try:

df = pd.DataFrame(data={'A':n,'B':t,'C':I})
df = df[df['C']>0]

This will only keep rows where I is positive

Upvotes: 1

Related Questions