Using Dyntools to Plot Many .OUT Files
I am trying to use Dyntools to plot each .OUT file in a directory, one by one. What I am doing is setting up my optnchn
dictionary, then looping through each .OUT file in the directory, creating a chnf
object, updating the filename, and calling .xyplots()
to plot it. This works fine, in the sense that I get a pdf file output for each .OUT file, but I get the following error:
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.
What ends up happening is that each subsequent plot is overlapping the previous plot. It seems to be 're-using' the previous plot that was created. The only way around this that I have found is to run each plot individually one by one. I have tried many things like moving the .xyplots()
call to its own function, and returning chnf
. I have also tried to put a .plots_close
after the plot is created, and this just terminates the program. Code is inserted below. Any ideas as to what I am missing?
# Create list with all .OUT files in directory
outlist = glob.glob(r'C:\Users\Manny\Documents\PRC-12\2019_____SPS_Effectiveness_Study\results\dynamics\Phase_I\_OUT\*.out')
# Setup Channels - Each .OUT file has 7 plots, with 6 channels each.
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': '2019 ___SPS Effectiveness Study - Phase I', 'dpi': 300, 'showttl': True}
# Set Filename for current .OUT file plot results
plotfile1 = r'C:\Users\Manny\Documents\PRC-12\2019____SPS_Effectiveness_Study\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')
Have you found a fix to your problem? I am having the same issue and I have not found a fix other than possibly rewriting code as mentioned in the answers.