Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to reduce font size in savefig code in pandas

I have created a correlation matrix in pandas using this code:

corr=data.corr()

I have then saved the correlation heatmap with this code

plt.figure(figsize=(16, 6))
mask = np.triu(np.ones_like(data.corr(), dtype=np.bool))
heatmap = sns.heatmap(data.corr(), mask=mask, vmin=-1, vmax=1, annot=True, cmap='BrBG')
heatmap.set_title('Correlation Heatmap', fontdict={'fontsize':18}, pad=16);

plt.savefig(dataQualityCheck+'correlationHeatmap.png', dpi=300, bbox_inches='tight', font = {'family' : 'normal', 'weight' : 'bold', 'size' : 8})

The heatmap looks like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

How can I modify (reduce, actually) the font size of the numbers inside the heatmap?

>Solution :

IIUC, there is the parameter annot_kws that you can pass to sns.heatmap and define the size in:

heatmap = sns.heatmap(data.corr(), mask=mask, vmin=-1, vmax=1, annot=True, cmap='BrBG', 
                      annot_kws={'size':5}) # replace 5 by any value as needed
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading