Search code examples
pythonnumpymatplotlibtime-series

How to plot the inverse of a timeseries


I have a timeseries that looks like this:

import matplotlib.pyplot as plt
import numpy as np

data = [
        0.0320312479743734,
        0.029813902801834047,
        0.029573831125162542,
        0.018995469145011157,
        0.027841876726597548,
        0.041286583291366696,
        0.04001532797701657,
        0.036066913162358105,
        0.05553811206482351,
        0.019244458235334605,
        0.0350094516761601,
        0.025880977045744658,
        0.00444492106908001,
        0.021624276996590197,
        0.024681835202500224,
        0.020811115973629057,
        0.022745881869923323,
        0.03943057672586292,
        0.025860359892249107,
        0.020410736033227295
    ]
plt.plot(data)

enter image description here

How, in python, can I create the inverse of this line and plot it? By inverse, I  mean something like this (please ignore the y-axis, it should be identical to the first one but I just vertically flipped the image for demonstration):

enter image description here

I do not mean the plot the line that is the opposite absolute distance, like this:

enter image description here


Solution

  • Not sure if there is a nifty numpy function for this, but you can do:

    inverse = np.array(data)
    inverse = inverse.max() - (inverse - inverse.min())
    plt.plot(inverse)
    

    Over the original data:

    enter image description here