I realized that the following line in my python plot script is the main bottleneck in my execution time. I wrote a small bash function that tracks the time of the output of any application and prints out the time-in-between the stdout prints. The plot script I am testing is (snippet) the following:
#!/bin/python##------------------------------------------------------------------------------print ("Start loading and importing")import syssys.stdout.flush()import matplotlib.pyplot as pltfrom matplotlib.gridspec import GridSpecprint ("Done")sys.stdout.flush()print ("Start building fig and gs")sys.stdout.flush()# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Basic Layout Definition ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~#sizeHeight=4600#aRation=1.6#myDpi=100#fig = plt.figure(figsize=(sizeHeight/myDpi, sizeHeight/aRatio/myDpi), dpi=myDpi)fig = plt.figure()print ("plt.fig done")sys.stdout.flush()gs = GridSpec(3, 2, width_ratios=[3, 1], height_ratios=[1, 1, 1], wspace=0.02, hspace=0.03)print ("gs done")sys.stdout.flush()print ("Done")sys.stdout.flush()Executing it with my bash script (ts) gives me the following:
~: ts python plotData.py[ 00s:509ms] : Start loading and importing[ 02s:041ms] : Done[ 00s:006ms] : Start building fig and gs[ 11s:727ms] : plt.fig done[ 00s:007ms] : gs done[ 00s:007ms] : DoneTo ensure that things were correct, I achieve the same with time:
~: time python plotData.pyStart loading and importingDoneStart defining settingsDoneStart building fig and gsplt.fig donegs doneDonereal 0m14.630suser 0m2.463ssys 0m2.146sFirst, I was expecting that the resolution and DPI I set takes so much time but what-ever I set for the resolution or DPI (lines which are commented), the time-consumption for the plt.figure() command is always around 11 s to 12 s.
Can we somehow optimize that? Unfortunately, on the headless node gnuplot is not working and I need to use python. Any ideas to increase the performance here?
The rest of the script performes quite fast and all 7 plots are created within a few milliseconds. So I am really worried why plt.picture() performes so bad here?