Skip to content Skip to sidebar Skip to footer

How Do I Visually Stack Multiple Line Graphs Above Each Other In Python?

I was having trouble creating a plot I need which has multiple line graphs. What I want is a way to graph each of these above the other (say one has a baseline of y=5 I want the n

Solution 1:

Here's one way. The key point is to use fill_between function and offset each plotted line with some margin (i*2 in this case). Also, plotting has to start from the top, hence the [::-1] in the arange slice.

t=linspace(-2*pi, 2*pi, 1000)
for i in arange(1, pi, 0.01)[::-1]:
    left = exp(-(t + (i - 1) * 2*pi)**2) * cos(t * i)**2 - 1
    right = exp(-(t - (i - 1) * 2*pi)**2) * cos(t * i)**2 - 1 
    vertical_offset = i*2
    fill_between(t, vertical_offset + left + right, facecolor='white')

Post a Comment for "How Do I Visually Stack Multiple Line Graphs Above Each Other In Python?"