Plot sine function using radians with xlim and ylim

Viewed 263

I would like to plot a sine function with xlim measured in radians:

import sympy as sp
from sympy.functions.elementary.trigonometric import sin

x    = sp.symbols('x')
eqn  = sin(x)
p    = sp.plot(eqn, xlim = (-2*sp.pi, 2*sp.pi), ylim = (-1, 1))

This blows up because of how I'm using pi. If I replace pi with a numerical approximation (e.g. 3.14), the plot displays correctly.

1 Answers

This looks like a bug in the handling of xlim. Perhaps it's not been noticed because xlim is rarely used, with the x-limits usually being passed in a tuple along with the symbol itself:

sp.plot(eqn, (x, -2*sp.pi, 2*sp.pi), ylim=(-1, 1))

works fine.

Related