43

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'?

Bonifacio2
  • 3,405
  • 6
  • 34
  • 54
dokondr
  • 3,389
  • 12
  • 38
  • 62

1 Answers1

76

Try this :

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

fig.savefig('test.pdf')
Ahmad
  • 8,811
  • 11
  • 76
  • 141
user666
  • 5,231
  • 2
  • 26
  • 35