Reputation: 39477
I have this small plotting program.
But when I run it I notice the labels on the X axis are incorrect.
They go from 0 to 5000 while actually I have the interval [-1.5, 1.5]
1... How can I fix that?
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-1.5, 1.5, 5000)
y1 = np.tan(x) * np.arctan(x)
y2 = x * x
plt.plot(y1)
plt.plot(y2)
plt.show()
2... Also, if I change the linspace to call
x = np.linspace(-mt.pi/2.0 + 1/(10**6), mt.pi/2.0 - 1/(10**6), 5000)
I get an even stranger and really incorrect plot.
Something gets messed up completely.
Why? I want to plot these 2 functions in the range (-pi/2, pi/2)
How do I do this?
Upvotes: 0
Views: 1143
Reputation: 3598
Try:
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-1.5, 1.5, 5000)
y1 = np.tan(x) * np.arctan(x)
y2 = x * x
plt.plot(x,y1)
plt.plot(x,y2)
plt.show()
Now x
axis values are is between -1.5 and 1.5.
Regarding strange plot in second case just notice that:
np.tan(-1.5)
-14.101419947171719
and:
np.tan(-mt.pi/2.0)
-1.633123935319537e+16
which is much much bigger.
Upvotes: 2