Am using sympy plotting backend. The graphs of functions are being inverted and I don’t know why. For example y=x^2 is upsidedown with the negative y axis on top.
from sympy import *
from sympy.parsing.sympy_parser import *
import spb
import sympy as sympy
def queryMatplotlibEq(qVal,labels, color, xBounds, yBounds):
toShow = None
if (labels == "true"):
toShow = "center"
qVal = qVal.replace('^', "**")
x, y = symbols('x y', real=True)
lhs, rhs = qVal.split('=')
lhs = eval(lhs)
rhs = eval(rhs)
expr = lhs - rhs
sols = solve(expr, y)
plot = spb.plot(*sols, (x, xBounds[0], xBounds[1]), {"color": f"{color}", "markersize": "1"}, legend=False, aspect="equal", ylim=(
yBounds[0], yBounds[1]), xlim=(xBounds[0], xBounds[1]), grid=toShow, show=False, adaptive=False, n=70000, is_point=True, axis_center=(0, 0))
plot.show()
question = "y=x**2"
x, y = symbols("x y")
# [[-2.0, 2.3], [26.75, 31.0]]
xExtents = [-13, 13]
yExtents = [10, -30]
queryMatplotlibEq(question,"true","blue" ,xExtents,yExtents)
>Solution :
yExtents gets passed to matplotlib’s set_ylim. If the first value is negative and the second is positive you’ll get what you expect. Instead, you specified the first value positive and the second value negative, hence you get a reverse y-axis.