3

I'm using Spyder's Ipython console to try to get some quick parametric plots of functions. For now I'm focusing on x = cos(t), y = sin(t). I ran the command

import sympy as sp
sp.init_session()
p = plotting.plot_parametric(cos(t),sin(t),(t,0,2*pi))

and I get an oblong plot of the curve.

If I enter

p.aspect_ratio = (1,1)
p.show()

nothing changes. I try other aspect ratios and still nothing changes.

After looking at this answer In sympy plotting, how can I get a plot with a fixed aspect ratio?

I tried following their instructions to try to leverage matplotlib and I get no errors. But when I enter

plt.show() 

nothing shows.

Community
  • 1
  • 1
Addem
  • 3,635
  • 3
  • 35
  • 58
  • In the current sympy version you can use `plot_parametric(cos(t), sin(t), (t, 0, 2 * pi), aspect_ratio=(1, 1))` – JohanC Oct 27 '21 at 06:14

2 Answers2

4

You need to use fig.show() to display the graph. The following example produces a graph with equal aspect ratio:

import sympy as sp
sp.init_session()
p = plotting.plot_parametric(cos(t),sin(t),(t,0,2*pi))
fig = p._backend.fig
ax = p._backend.ax
ax.set_aspect('equal')
fig.show()

h/t to Sympy and plotting

Community
  • 1
  • 1
Craig
  • 4,605
  • 1
  • 18
  • 28
1

This works also

from sympy import*
t=symbols('t')
p = plot_parametric(cos(t),sin(t),show=False)
p.aspect_ratio=(1,1)
p.show()
  • 1
    It's generally considered a bad idea to use `from X import *`, because you're potentially importing a lot more symbols than you might expect. Best practice is to use either `import X` and then qualify the names when you use them, like `X.some_function()`, or else use `from X import some_function`. – joanis May 18 '22 at 21:58