我使用sympy绘图后端。函数的图形被颠倒了,我不知道为什么。例如y=x^2是upsidedown,负y轴在上面。
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)
字符串
1条答案
按热度按时间9njqaruj1#
yExtents
被传递给matplotlib的set_ylim
。如果第一个值为负,第二个值为正,那么您将得到您所期望的结果。相反,您指定了一个正的第一个值和一个负的第二个值,因此您得到了一个反向的y轴。