I want to plot columns of a pandas dataframe by a calling a function. A data frame is passed to a function and manipulated. A plot and the manipulated data frame is returned:
from matplotlib import pyplot as plt
import pandas as pd
def custom_plot(df):
tmp = df.plot(kind = 'bar')
plt.legend(title = "Test")
return [tmp,df]
df = pd.DataFrame( {'x' : [1,2,3]})
p,d = custom_plot(df)
Executing this code displays this plot although I do not want it to be displayed:
I want to plot the returned object p
in the Jupyter notebook by calling something like p.show()
. There are 2 problems:
The plot is always displayed when
custom_plot()
is called although I do not want it to be plotted.When I want to plot
p
by callingp.show()
this does not work. I am told AttributeError: 'AxesSubplot' object has no attribute 'show'
How can this behavior be achieved?