如何保存用'pandas.DataFrame.plot'创建的图像?

dok*_*ndr 8 python plot pandas

尝试使用'pandas.core.series.Series'对象中的'pandas.DataFrame.plot'创建的绘图图像时:

%matplotlib inline
type(class_counts) # pandas.core.series.Series
class_counts.plot(kind='bar',  figsize=(20, 16), fontsize=26)
Run Code Online (Sandbox Code Playgroud)

像这样:

import matplotlib.pyplot as plt
plt.savefig('figure_1.pdf', dpi=300)
Run Code Online (Sandbox Code Playgroud)

导致空的pdf文件.如何保存用'pandas.DataFrame.plot'创建的图像?

use*_*666 17

试试这个 :

fig = class_counts.plot(kind='bar',  figsize=(20, 16), fontsize=26).get_figure()

fig.savefig('test.pdf')
Run Code Online (Sandbox Code Playgroud)