1

I want to save the table of DataFrame as a picture and I get inspired from this question.
But sadly, the table picture I draw is so vague and I can't make it clear.
This is my environment:

Python 3.7.0
pandas 0.23.0
matplotlib 2.2.2

And here is my code, its table and my picture:

train_corr
         Survived    Pclass      Age         SibSp       Parch      Fare
Survive  1.000000   -0.338481   -0.077221   -0.035322    0.081629    0.257307
Pclass  -0.338481    1.000000   -0.369226    0.083081    0.018443   -0.549500
Age     -0.077221   -0.369226    1.000000   -0.308247   -0.189119    0.096067
SibSp   -0.035322    0.083081   -0.308247    1.000000    0.414838    0.159651
Parch    0.081629    0.018443   -0.189119    0.414838    1.000000    0.216225
Fare     0.257307   -0.549500    0.096067    0.159651    0.216225    1.000000
from pandas.plotting import  table

ax = plt.subplot(111, frame_on=False) # no visible frame
ax.xaxis.set_visible(False)  # hide the x axis
ax.yaxis.set_visible(False)  # hide the y axis

table(ax, train_corr, loc='center')  

plt.savefig('correlation_matrix_HD.jpg')

enter image description here

And I have searched documentation about pandas.plotting and matplotlib.pyplot.table, but I still don't know how to figure it out.
If not mind, could anyone help me?
Thanks sincerely.

Bowen Peng
  • 1,635
  • 4
  • 21
  • 39

2 Answers2

1

You can adjust the dpi parameter in savefig() to adjust the resolution of the plot.

From the documentation

dpi : [ None | scalar > 0 | 'figure' ]

The resolution in dots per inch. If None, defaults to rcParams["savefig.dpi"]. If 'figure', uses the figure's dpi value.

plt.savefig('correlation_matrix_HD.jpg',dpi=600)

Play around with the dpi value to suit your need.

Bitto
  • 7,937
  • 1
  • 16
  • 38
1

You will want to play with the figure size and figure dpi

fig = plt.figure(figsize=(8,6), dpi=144)
ax = fig.add_subplot(111, frame_on=False) 

change the values until you're satisfied. For the interplay between the two see Relationship between dpi and figure size.

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712