Home > Software design >  plot multiple density functions in one plot
plot multiple density functions in one plot

Time:01-20

i would like to plot multiple density functions in one matplotlib plot. I am currently using:

    def get_probability(self, df):
        df.plot.density() 

Now i got multiple plots in seperated windows. How i am able to get multiple density functions in one plot ?

I would be grateful for any help !

CodePudding user response:

If you create, or get the current Axes object, you can pass that to plot.density to plot on the same figure, e.g.,

def get_probability(self, df):
    from matplotlib import pyplot as plt  # you could add this at the top of your script
    ax = plt.gca()  # get current Axes
    df.plot.density(ax=ax)  # pass it to density

CodePudding user response:

Thank you. I solved the problem by using ax objects.

  • Related