Reputation: 37
I would like to make a plot with three different graphs in it. This is my code:
import numpy as np
from math import sqrt
import matplotlib.pyplot as plt
def make_sequence(N:int, alpha:float, beta:float) -> np.ndarray:
z_n = np.empty((N, 1))
for n in range(1, N+1):
z_n[n-1] = alpha*(1+sqrt(3))**n + beta*(1-sqrt(3))**n
return z_n
x0 = make_sequence(50, 0.0, 1.0)
x1 = make_sequence(50, 0.0, 99.0)
x2 = make_sequence(50, 5.0, 5.0)
plt.plot(x0, 'bo')
plt.plot(x1, 'ro')
plt.plot(x2, 'go')
plt.axis([0, 50, -2, 2])
plt.title(r'$z_1,...,z_{50}$')
plt.xlabel('n')
plt.legend([r'$\alpha =0$, $\beta =1$', r'$\alpha =0$, $\beta =99$', r'$\alpha =5$, $\beta =5$'])
plt.show()
Why does x2 not show up on the plot?
If I try to plot x2 alone it only shows if I remove the axis-scaling command.
Upvotes: 1
Views: 27
Reputation: 339705
Printing min(x2)
and max(x2)
shows that x2
ranges from 10
to ~3.3e22
. However, your y axis only goes from -2
to 2
. Hence none of the values from x2
are in the visible range.
You may of course change the scale to plt.axis([0, 50, -2, 3.5e22])
, which would result in
But then, x0
and x1
are not well seen in the plot anymore. You need to decide for yourself, if it makes sense to plot all 3 series in the same plot.
Upvotes: 1