I have a function which plots and displays the distribution using the distplot from seaborn. it looks like this
def getPlot(data):
x=sns.distplot(data, hist=False)
plt.show()
return x
every time I call the function I get a plot of the distribution.
I want some help in modifying the function so that at the end of calling the function multiple times I should get an extra plot which is the combination of all the previous plots.
So if my function calls were
getPlot(data1)
getPlot(data2)
getPlot(data3)
I should get the individual plots for the data as I call the function and also at the very end I want the plots for the 3 data to be superimposed on each other.
Just moving plt.show() outside the function will not suffice because I want individual plots of the separate data as well as one figure that contains all the data.
getPlotdoes not know whether there will be more calls or not.plt.show()at the end to get the final plot.plt.show()insidegetPlotand closed the figures so an additional call would have nothing to show. Maybe you can write a new function (let's call itgetAllPlots) that takes a list (or iterble) of datasets and plots their distributions superimposed, then callgetAllPlots([data1, data2, data3])at the end. Would that work?plt.show()inside the function then I will lose the individual plots for each of thedataand the end get a combination of all the plots alone at the very end. But I want both of them, the combination as well as the individual data.plt.show()only at the end, but you need separate figures. The simplest solution is to create a separate figure and axes first before calling any of the functions, and passing that axes into each function, and the function both plots the data into that axes as well as into a brand new figure. I'll vote to reopen the question because then it's not a duplicate.