我想将DataFrame的表格保存为图片,我的灵感来自this question .
但遗憾的是,我画的表格太模糊了,看不清。
这是我的环境:
Python 3.7.0
pandas 0.23.0
matplotlib 2.2.2
这是我的代码、它的表格和我的图片:
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')
我搜索了有关 pandas.plotting 的文档和 matplotlib.pyplot.table ,但我还是不知道如何解决。
如果不介意的话,有人可以帮助我吗?
衷心感谢。
最佳答案
您将需要调整图形大小和图形 dpi
fig = plt.figure(figsize=(8,6), dpi=144)
ax = fig.add_subplot(111, frame_on=False)
更改值直到您满意为止。有关两者之间的相互作用,请参阅 Relationship between dpi and figure size .
关于python - DataFrame的表格保存为图片时如何让图片清晰,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55813270/