~~ I'm sorry if I misunderstood. ~~ I lacked my knowledge. We received a comment from @SaitoTsutomu and solved.
Start jupyter notebook
. First of all, preparation.
from sympy.plotting import plot, plot_implicit, plot_parametric
from sympy import symbols, sin, cos, pi
x, y, t = symbols('x y t')
plot
plot(x**2, (x, -2, 2))
Then, $ y = x ^ 2 $ in the range of $ -2 \ leqq x \ leqq 2 $ is drawn.
It is also possible to display graphs of multiple functions at the same time. Draw $ y = x ^ 2 $ and $ y = x $ in the same coordinate space.
plot(x**2, x, (x, -2, 2))
plot_implicit
You can also draw figures in the form of $ f (x, y) = 0 $ (so-called implicit functions). Next is $ x ^ 2 + y ^ 2-1 = 0 $, that is, a circle with a radius of $ 1 $ centered on the origin.
plot_implicit(x**2+y**2-1)
I'm concerned about the aspect ratio, but it's a circle. It seems that plot_implicit
cannot set two or more expressions and draw multiple curves. Does the implicit function mean that plotting is troublesome?
plot_parametric
This is my favorite. If $ y = f (x)
plot_parametric(cos(t), sin(t), (t, 0, 2*pi))
You can draw multiple curves at the same time.
plot_parametric((cos(t), sin(t)), (cos(t)+1, sin(t)+1), (t, 0, 2*pi))
It is also possible to set the parameter range individually.
plot_parametric((cos(t), sin(t), (t, 0, 2*pi)), (cos(t)+1, sin(t)+1, (t, 0, pi)))
By the way, I'm sure some of you have been interested in it for a long time, but you can see an ellipse even though you should be plotting a circle. According to the official documentation
aspect_ratio : tuple of two floats or {‘auto’}
There is, but nothing changes even if this is set ...
plot_parametric((cos(t), sin(t)), (cos(t)+1, sin(t)+1), (t, 0, 2*pi), axis=False, aspect_ratio=(1, 1))
I can confirm that the ʻaxis option is applied, but ʻaspect_ratio
does not respond. I searched on Google, but it was only an English site, so I looked through it for a while, but I couldn't get a clear answer.
In the first place, sympy plot seems to mediate matplotlib, so forcibly change the matplotlib settings? There was an answer like this, but I thought it would be better to illustrate it with matplotlib from the beginning if I wanted to do it.
It's my opinion of an amateur who is neither a programmer nor anything, but even if I insert a keyword that I did not expect to be ** kwargs
, no particular error occurs. I think it's a pretty dangerous specification ... I thought about spelling mistakes in ʻaspect_ratio, but I didn't say yes or no, so I wasn't even sure if I was aware of the option ʻaspect_ratio
.
The screen size is different from aspect_ratio.
from sympy.plotting import plot_parametric
from sympy import symbols, sin, cos, pi
t = symbols('t')
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = (8,8)
plot_parametric(cos(t), sin(t), (t, 0, 2*pi))
It was displayed safely at $ 1: 1 $. Thank you, @SaitoTsutomu.
Recommended Posts