In python pandas, how to save the "grid"?

I am new to pandas build functions, in the document, this command is really convenient:

myplot = rts.ret.hist(bins=50, by=rts.primary_mic)

however, problems arise when I try to get a link to a shape from a chart and save it:

myfigure = myplot.get_figure()
AttributeError: 'numpy.ndarray' object has no attribute 'get_figure'

I understand that rts.ret.hist (bins = 50) returns a plot object, and rts.ret.hist (bins = 50) returns an array object.

How do I save a figure in this case?

any clue?

thank!

+1
source share
1 answer

To save the shape, you can use plt.savefig:

import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame(
    [(1, 2), (1, 3), (1, 4), (2, 1), (2, 2)], columns=['col1', 'col2'])
df.hist(bins=4, by=df['col1'])
plt.savefig('/tmp/out.png')

enter image description here

+2
source

Source: https://habr.com/ru/post/1599387/


All Articles