如何使所有四个象限在以x轴和y轴为中心的图形中可见

时间:2019-03-25 19:00:04

标签: python python-3.x matplotlib

我需要两个轴都在中间的图形中显示,以便在它们相交时在中间形成十字形(这样我就可以在几何上表示二次图的零)我使用的代码,我该如何对其进行编辑,以使图的结果类似于我的预期结果

import math
import matplotlib.pyplot as plt

z = float(input("Enter the value of x    "))
a = float(input("Enter the value of a    "))
b = float(input("Enter the value of b    "))
c = float(input("Enter the value of c    "))
x = []
y = []
for i in range(-1000, 1000, 1):
    x.append(i)
    t = (a * (i ** 2)) + (b * i) + c
    y.append(t)

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)

ax.spines['left'].set_position('center')
ax.spines['bottom'].set_position('zero')

ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')

ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')

plt.plot(x, y)
plt.show()

我希望图表像这样

Graph of a quadratic function with two real roots

但是,这是一种输出

Graph with no lower two quadrants

0 个答案:

没有答案