I have a function in my code that grabs a CSV file (with pandas) and charts it using matplotlib.
Before the plt.show() line, I’m configuring how the chart looks (note that I have an INI file where I grab the numeric values from for some of these settings):
plt.title(plotTitle,
fontsize=chartTitleFontSize,
pad=chartTitlePadding)
plt.yticks(fontsize=chartTickLabelsFontSize)
plt.xticks(fontsize=chartTickLabelsFontSize)
plt.text(0.01, 0.99,
"Print Date: " + str(intDate.upper()),
fontsize=12,
horizontalalignment='left',
verticalalignment='top',
transform=plt.gca().transAxes,
bbox=dict(facecolor='yellow',
alpha=0.5,)
)
plt.ylabel(yAxisLabel,
fontsize=chartAxisLabelFontSize,
labelpad=float(chartYaxisLabelPadding))
print(tab1a + 'Generating the X-axis label...')
plt.xlabel(frequencyFileHeader,
fontsize=chartAxisLabelFontSize,
labelpad=float(chartXaxisLabelPadding))
plt.legend(loc='upper center',
bbox_to_anchor=(0.5, -0.05),
fancybox=True,
shadow=True,
ncol=10,
prop={'size': chartLegendFontSize})
plt.grid(which='major', axis='both', linestyle='-', linewidth=1.5)
plt.minorticks_on()
plt.grid(which='minor', axis='both', linestyle='--', linewidth=1)
plt.xticks(ticks=[0.15, 1, 10, 80],
labels=['0.15', '1', '10', '80'])
plt.rcParams["figure.dpi"] = chartPlotDPI
plt.rcParams["savefig.dpi"] = chartSaveDPI
plt.show()
The function works great the first time:
However, when the function is called a second time, all my previous formatting disappears:
I have no idea if there’s something I’m doing wrong or if it’s a limitation of matplotlib.
I need to call the function a second time so that I can grab a different CSV file to chart, independent of the first one (or previous charts).