How to save image created with 'pandas.DataFrame.plot'?

Question:

When trying to save plot image created with ‘pandas.DataFrame.plot’ from ‘ pandas.core.series.Series’ object :

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

Like this:

import matplotlib.pyplot as plt
plt.savefig('figure_1.pdf', dpi=300)

results in empty pdf file. How to save image created with ‘pandas.DataFrame.plot’?

Asked By: dokondr

||

Answers:

Try this :

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

fig.savefig('test.pdf')
Answered By: user666
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.