I would like to know why this python code:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
x = np.arange(-3,3,100)
y = -(np.arctan(-1/x))
plt.ylim((-1.5,1.5))
plt.plot(x,y)
plt.show()
renders an empty plot, with the axes having my desired limits. Wolfram Alpha assures me that the function should be visible within these limits. I am completely lost here.
Your range contains only a single point x = [-3]
, hence you won't plot much. What you want is to create a linear space using
x = np.linspace(-3,3,100)
Then your function will be visible.
Edit: Explanation of the first sentence:
np.arange(start, stop, step)
This will create a range starting at start
, stopping at stop
(exclusive) and stepping by step
. Thus you start with -3
, the next value must be at stride -3 + 100 = 97
, but this is not smaller than 3
. Thus the range only contains the start number.
np.linspace(start, stop, number)
instead will create a range in the interval [start,stop]
divided equidistant in number
partitions.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加