简体   繁体   English

使用 IF 语句分离从文本文件中读取的负值和正值

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

In the following code I contains positive and negative values.在下面的代码中, I包含正值和负值。 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.我定义了一个IF但它不起作用,并且在最终图中我再次具有所有负值和正值。 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
if (I>0).any()

Basically asks if there is any positive number in I .基本上询问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这只会保留我为正的行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM