Skip to content
Advertisement

Matplotlib flattens the first of two plots when I add the second plot?

Matplotlib madness…

JavaScript

The expected plot

However, when I try to run a cumulative plot of any kind, MPL flattens the first plot and plots the second relative to it:

JavaScript

Undesirable type of plot

I’m doing stock analysis, and trying to plot returns relative to the existing closing price. I don’t understand why MPL is flatting the first plot – or how to make it stop.

Thanks for any help.

Advertisement

Answer

It’s not flattening it per se. But the scale of the second line/plot is much bigger than the first that it shows like it’s flattened.

You will need to use multiple scales (multiple y axis).

Check out this example from the matplotlib documentation.

Basically, you will need to do something like this:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement