Matplotlib 需要正确的x&;循环中的y标签

Matplotlib 需要正确的x&;循环中的y标签,matplotlib,Matplotlib,我试图用我掌握的数据创建21个散点图。这21个图有不同的数据组合,我成功地创建了正确的图。然而,我一辈子都不知道如何正确地标注这些情节。这是我的密码: F225W = np.loadtxt('path/phot_F225W.dat',usecols=[0], unpack=True) F275W = np.loadtxt('path/phot_F275W.dat',usecols=[0], unpack=True) 。。。我对所有过滤器都这样做 Filters = [F225W,F275W,F

我试图用我掌握的数据创建21个散点图。这21个图有不同的数据组合,我成功地创建了正确的图。然而,我一辈子都不知道如何正确地标注这些情节。这是我的密码:

F225W = np.loadtxt('path/phot_F225W.dat',usecols=[0], unpack=True)
F275W = np.loadtxt('path/phot_F275W.dat',usecols=[0], unpack=True)
。。。我对所有过滤器都这样做

Filters = [F225W,F275W,F336W,F438W,F606W,F814W,F850L]

for i in range(len(Filters)):

    for j in range(len(Filters)):
        B = Filters[i]
        R = Filters[j]

        BR = B-R

        if j<=i:
            pass
        else:
            plt.figure()
            plt.gca().invert_yaxis()
            plt.xlim(-6,6)
            plt.ylim(-4,-15)
            plt.xlabel(str(Filters[i]) + '-' + str(Filters[j]))
            plt.ylabel(str(Filters[j]))  
            plt.plot(BR,R,'k.',markersize=1)

plt.show()
过滤器=[F225W、F275W、F336W、F438W、F606W、F814W、F850L]
对于范围内的i(len(过滤器)):
对于范围内的j(透镜(过滤器)):
B=过滤器[i]
R=过滤器[j]
BR=B-R

如果j对评论进行扩展,这是否可以作为解决方案?循环将暂停,直到您关闭每次迭代中弹出的每个图形(如果您保留plt.show())。您也可以保存每个图形,并按照解决方案中的指示分别查看它们:

Filters = [F225W,F275W,F336W,F438W,F606W,F814W,F850L]
Filter_names = ['F225W','F275W','F336W','F438W','F606W','F814W','F850L']

for i in range(len(Filters)):

    for j in range(len(Filters)):
        B = Filters[i]
        BB = Filter_names[i]
        R = Filters[j]
        RR = Filter_names[j]

        BR = B-R

        if j<=i:
            pass
        else:
            plt.figure()
            plt.gca().invert_yaxis()
            plt.xlim(-6,6)
            plt.ylim(-4,-15)
            plt.xlabel(str(Filter_names[i]) + '-' + str(Filter_names[j]))
            plt.ylabel(str(Filter_names[j]))  
            plt.title('B filter:' + BB + '\tR Filter:' + RR)
            plt.plot(BR,R,'k.',markersize=1)

            os.chdir(path_you_want_to_save_to)
            plt.savefig('B_' + BB +'_R_' + RR + '.png')

            #uncomment line to see graph and pause loop.
            #also note the indentation has changed
            #plt.show()
            plt.close()
过滤器=[F225W、F275W、F336W、F438W、F606W、F814W、F850L]
过滤器名称=['F225W'、'F275W'、'F336W'、'F438W'、'F606W'、'F814W'、'F850L']
对于范围内的i(len(过滤器)):
对于范围内的j(透镜(过滤器)):
B=过滤器[i]
BB=过滤器名称[i]
R=过滤器[j]
RR=过滤器名称[j]
BR=B-R

如果jDid,您尝试将plt.show()缩进到迭代for循环的j中?我认为它会进行大量的策划,并且只会在最后向你展示。可能每次都会覆盖x和y标签?我尝试过移动它,但它无法解决我的问题。您是否尝试过为标签使用字符串列表,如下面使用过滤器名称列表的列表?