如何创建Matplotlib轴的新实例?

2024-04-29 03:41:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用一个名为PSSE的电力系统仿真软件,其中包括一个名为dyntools的模块,它基于Matplotlib。我正在尝试使用Dyntools来逐个打印目录中的每个.OUT文件(.OUT file是一个PSSE文件,其中包含dyntools可以处理的数据)。在

我正在做的是设置我的optnchn字典(通道选项:一个dyntoolschnf的属性,它告诉我想从.OUT文件中提取什么信息)。然后循环访问目录中的每个.OUT文件,创建一个chnf对象,更新文件名,并调用chnf函数xyplots来绘制它。这很好,因为我为每个.OUT文件都得到了一个pdf文件输出,但是我得到了以下错误:

C:\Python34\lib\site-packages\matplotlib\cbook\deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.

结果是,每个后续文件都从其.OUT文件中打印了正确的数据,但文件顶部的标题与前一个文件重叠。Dyntools将头应用于包含.OUT文件路径和其他信息的PDF文件。这就变成了一个无法读取的混乱,因为它不断地在前一个文件的头上写入新的头。有什么办法可以克服这个问题吗?在

规范说明:

  • PSSE为变量ierr分配一个错误代码,如果发现错误,则计算True,如果没有错误,False。在这段代码中,这总是计算到False
    # Create list with all .OUT files in directory
    outlist = glob.glob(r'C:\Users\Manny\Documents\PRC-12\2019_Snf_RAS_Effectiveness\results\dynamics\Phase_I\_OUT\*.out')

    # Setup Channels
    optnchn = {1:{'chns':[7,9,53,55,59,79]},
                2:{'chns':[15,25,37,39,71,73]},
                3:{'chns':[17,43,47,57,65,75]},
                4:{'chns':[92,93,95,96,107,115]},
                5:{'chns':[98,102,104,111,112,114]},
                6:{'chns': [100,103,105,109,119,120]},
                7:{'chns': [81,83,85,86,88,89]}
                }

    # Counter for filenames
    j = 1

    # Loop thru each .OUT file
    for i in outlist:

        # Create object with current out file, set options
        chnf = dyntools.CHNF(i)
        optn = {'size': 'Letter', 'orientation': 'Landscape', 'title': 'SNF RAS - Phase I', 'dpi': 300, 'showttl': True}

        # Set Filename for current .OUT file plot results
        plotfile1 = r'C:\Users\Manny\Documents\PRC-12\2019_Snf_RAS_Effectiveness\results\plot_logs\PHASE I\SimPlots'
        plotfile2 = j
        plotfile3 = '.pdf'
        plotfile = plotfile1 + str(plotfile2) + plotfile3
        j = j+1

        # Produce Plot
        ierr = chnf.xyplots(optnchn, optn, plotfile)

        if ierr:
            print('Errors Were Found')

        else:
            print('No Errors Found')

更新:下面是来自PSSE的chnf文档的chnf部分:

^{pr2}$

Tags: 文件theinstanceforoutresultspssefile