I wrote a function that took a dataframe generated from Pandas and produce a heatmap:
def drawHeatMap(df, city, province, collector, classtype, color, titleposy):
try:
thePlot = pl.matshow(df.values, cmap='PuBuGn')
pl.colorbar(thePlot, orientation='vertical')
aTitle = (classtype + ' Composition Changes Over Time in ' + city +
', ' + province + '
' + collector + ' collector. ' + 'rs100')
pl.title(aTitle, x=0.5, y=titleposy, style='oblique', weight='bold')
pl.xlabel('Collection Time')
pl.xticks(range(len(df.columns)), df.columns, rotation=90)
pl.yticks(range(len(df.index)), df.index)
fileName = (classtype + '-' + city + '-'
+ province + '-' + collector + '.png')
pl.savefig(fileName)
except ZeroDivisionError:
errorMessage = ('No Data Avaiable for ' + city + ', ' + province +
' with ' + collector + ' collector.')
print errorMessage
The problem I am having is, savefig()
would save figures with the axis and graphics trimmed. I have to use show()
, maximize the graph and manually save the figure with the GUI button myself.
How can I fix my function so savefig()
would save the graphs properly? I tried to put a line like this before pl.savefig()
to control my figure:
pl.figure(figsize=....)
but I end up producing some empty graphs. What is the proper way to write a matplotlib function that give me full control on saving the figure?
Updated with Example of a problem figure:
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…