Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 897
dokondr Avatar asked Jul 28 '17 14:07

dokondr


People also ask

How do I save a DataFrame as a PNG in Python?

To save a pandas DataFrame table as a png with Python, we can use the data frame export method in the dataframe_image package. Then we call df. style. background_gradient to style the data frame table with a background gradient.

How do you save a graph as a picture in Python?

Now if you want to save matplotlib figures as image files programmatically, then all you need is matplotlib. pyplot. savefig() function. Simply pass the desired filename (and even location) and the figure will be stored on your disk.

How do I save pandas DataFrame to image?

Pass your normal or styled DataFrame to the export function along with a file location to save it as an image. You may also export directly from the DataFrame or styled DataFrame using the dfi. export and export_png methods, respectively. Here, an example of how exporting a DataFrame would look like in a notebook.


1 Answers

Try this :

fig = class_counts.plot(kind='bar',           figsize=(20, 16), fontsize=26).get_figure()  fig.savefig('test.pdf') 
like image 197
user666 Avatar answered Sep 20 '22 12:09

user666