If I have a function such as sin(1/x)
I want to plot and show close to 0, how would I smooth out the results in the plot? The default number of sample points is relatively small for what I'm trying to show.
Here's the code:
from sympy import symbols, plot, sin
x = symbols('x')
y = sin(1/x)
plot(y, (x, 0, 0.5))
As x
approaches 0, the line becomes more jagged and less "curvy". Is there some way to fix this?
You can set the number of points used manually:
plot(y, (x, 0.001, 0.5), adaptive=False, nb_of_points=300000)
Note: I expected to get ZeroDivisionError when using the exact question-code (that is, having x go from 0 to something), but i don't get an error (strange). I do get the error though as soon as I use adaptive=False, nb_of_points=300000
, so this is why I set xmin to a non zero value (0.001
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With