'Why does my sympy plot have an axis in the middle?
I'd like to specify the x limits of a sympy plot:
plot(normal(x=x,mean=10,sigma=5), (x, 0,20))
... but the is rendered with the x axis at y=0.5. What's up with that?
Full example:
%matplotlib inline
import sympy
from sympy import symbols
from sympy import plot
def normal(x, mean, sigma):
z = (x - mean) / sigma
return (1 / (sigma * sympy.sqrt(2 * sympy.pi))) * sympy.exp(-(z * z) / 2)
x = symbols("x")
p1 = plot(normal(x=x,mean=10,sigma=5), (x, 0,20),
# ylim=(0,1), xlim=(0,20) # No help
)
I found this (related) sympy.plotting.plot strange xlabel position but it refers to an older version of sympy.
Solution 1:[1]
I think SymPy is trying to mimic Mathematica's plots, in which the intersection of the axis is placed somewhere inside the figure. Sometimes, the algorithm produces this weird visualizations.
You can control the intersection of the axis with the axis_center keyword argument, which can accept:
"auto": the default choice, in which the algorithm tries to select a smart location."center": the intersection of the axis will be placed in the middle of the figure.- a tuple
(x_coord, y_coord).
Even with the tuple, it might be difficult to place the horizontal axis on the bottom of the figure and get a decent plot out of it. If you'd like, you can try my SymPy Plotting Backends module, which uses the default matplotlib style.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Davide_sd |

