matplotlib 在错误位置绘制X轴的症状?

xj3cbfub  于 2023-06-23  发布在  其他
关注(0)|答案(1)|浏览(88)

我正在使用Sympy绘制一个函数,X轴远远高于它应该在的位置。y轴的编号是正确的,但由于某些原因,x轴是zeroed,在28.75左右。我试过设置axis_center=“auto”而不是“center”,但没有改变。

from sympy import *
from sympy.parsing.sympy_parser import *
import spb
import sympy as sympy



question = "100*(x)**2-30*x+30"

x,y = symbols("x y")
# [[-2.0, 2.3], [26.75, 31.0]]

plot = spb.plot(eval(question), (x, -2.0, 2.3), {"color": f"blue", "markersize": "1"}, legend=False, aspect="equal", ylim=(
                26.75, 31), xlim=(-2.0, 2.3), show=True, adaptive=False, n=70000, is_point=True,axis_center="auto")
wd2eg0qa

wd2eg0qa1#

Here you can read the documentation关联到MatplotlibBackend,默认情况下由spb使用。特别是:

axis_center(float, float) or str or None, optional
    Set the location of the intersection between the horizontal and vertical axis in a 2D plot. It can be:

        * None: traditional layout, with the horizontal axis fixed on the bottom and the vertical axis fixed on the left. This is the default value.
        * a tuple (x, y) specifying the exact intersection point.
        * 'center': center of the current plot area.
        * 'auto': the intersection point is automatically computed.

让我们运行一个简单的代码片段来可视化差异:

from sympy import *
import spb
question = "100*(x)**2-30*x+30"

x,y = symbols("x y")

create = lambda axis_center: spb.plot(eval(question), (x, -2.0, 2.3),
     legend=False, aspect="equal",
     ylim=(26.75, 31), xlim=(-2.0, 2.3), adaptive=False,
     is_point=False,axis_center=axis_center, show=False,
    title=f"axis_center={axis_center}")
p1 = create(None)
p2 = create("center")
p3 = create("auto")
p4 = create((0, 28))
spb.plotgrid(p1, p2, p3, p4, nc=2)

显然,您可以看到"auto""center"之间的差异。我想你必须使用元组来设置你想要的位置的交集的位置。

相关问题