Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Matplotlib绘制抛物线的Python_Matplotlib - Fatal编程技术网

使用Matplotlib绘制抛物线的Python

使用Matplotlib绘制抛物线的Python,matplotlib,Matplotlib,如何使用此函数构建图形?谢谢!:)我试过了,但我不知道该如何使用: def二次型(a、b、c): 尝试: d=b**2-4*a*c 凸_点=-b/(2*a) 如果(d==0): 凸_点=-b/(2*a)#当det为0时,它是x-拦截器 打印('凸点在',凸点在',x轴上,'抛物线在',c'与y轴相交,'行列式为0'); elif(d

如何使用此函数构建图形?谢谢!:)我试过了,但我不知道该如何使用:

def二次型(a、b、c):
尝试:
d=b**2-4*a*c
凸_点=-b/(2*a)
如果(d==0):
凸_点=-b/(2*a)#当det为0时,它是x-拦截器
打印('凸点在',凸点在',x轴上,'抛物线在',c'与y轴相交,'行列式为0');
elif(d<0):
print(‘行列式为’,d,’,若行列式小于零,则不存在实解);
其他:
x_正=(-b+数学sqrt(d))/(2*a)#y=0
x_负值=(-b-数学sqrt(d))/(2*a)#y=0
打印('凸点位于',凸点',在x轴上| x | U正',x | U正',| x | U负',x | U负',|抛物线在',c处与y轴相交)
除:
打印('try:import math');
def二次型(a、b、c):
尝试:
将matplotlib.pyplot作为plt导入
输入数学
将numpy作为np导入
d=b**2-4*a*c
凸_点=-b/(2*a)
x=np.linspace(-50,50,1000);
y=a**2+b*x+c
图,ax=plt.子批次();
轴图(x,y)
如果(d==0):
凸_点=-b/(2*a)#当det为0时,它是x-拦截器
打印('凸点在',凸点在',x轴上,'抛物线在',c'与y轴相交,'行列式为0');
elif(d<0):
print(‘行列式为’,d,’,若行列式小于零,则不存在实解);
其他:
x_正=(-b+数学sqrt(d))/(2*a)#y=0
x_负值=(-b-数学sqrt(d))/(2*a)#y=0
打印('凸点位于',凸点',在x轴上| x | U正',x | U正',| x | U负',x | U负',|抛物线在',c处与y轴相交);
除:
打印('try:import math')
但它不显示以下图形:S

def quadratic(a、b、c):
def quadratic (a, b, c):
try:
    import matplotlib.pyplot as plt
    import math
    import numpy as np
    d = b**2-4*a*c
    convex_point = -b/(2*a)
    x = np.linspace(-10, 10, 1000);
    y = a**2 + b*x + c
    fig, ax = plt.subplots();
    ax.plot(x, y);
    plt.show()
    if(d == 0):
        convex_point = -b/(2*a) #it is the x-interceptor when det is 0
        print('the convex point is at',convex_point, 'on the x-axis | the parabola intersect the y-axis at',c, '| the determinant is 0');
    elif(d < 0):
        print('Determinant is', d,'and if determinant is smaller than zero, there is no real solution');
    else:
        x_positive = (-b+ math.sqrt(d))/(2*a); # y = 0
        x_negative = (-b- math.sqrt(d))/(2*a); # y = 0
        print('the convex points is at',convex_point, 'on the x-axis |x_positive',x_positive,' |x_negative',x_negative,'| the parabola intersect the y-axis at',c);
except:
    print('try: import math')
尝试: 将matplotlib.pyplot作为plt导入 输入数学 将numpy作为np导入 d=b**2-4*a*c 凸_点=-b/(2*a) x=np.linspace(-10,10,1000); y=a**2+b*x+c 图,ax=plt.子批次(); ax.图(x,y); plt.show() 如果(d==0): 凸_点=-b/(2*a)#当det为0时,它是x-拦截器 打印('凸点在',凸点在',x轴上,'抛物线在',c'与y轴相交,'行列式为0'); elif(d<0): print(‘行列式为’,d,’,若行列式小于零,则不存在实解); 其他: x_正=(-b+数学sqrt(d))/(2*a)#y=0 x_负值=(-b-数学sqrt(d))/(2*a)#y=0 打印('凸点位于',凸点',在x轴上| x | U正',x | U正',| x | U负',x | U负',|抛物线在',c处与y轴相交); 除: 打印('try:import math')

此代码有效:)

尝试在您的
ax.plot
行之后添加一个
plt.show()
。我尝试过,但它引发了一个异常,当我删除它时,它再次正常。谢谢,解决了我错误地使用ax.show而不是plt.show的问题^^
def quadratic (a, b, c):
try:
    import matplotlib.pyplot as plt
    import math
    import numpy as np
    d = b**2-4*a*c
    convex_point = -b/(2*a)
    x = np.linspace(-50, 50, 1000);
    y = a**2 + b*x + c
    fig, ax = plt.subplots();
    ax.plot(x, y)
    if(d == 0):
        convex_point = -b/(2*a) #it is the x-interceptor when det is 0
        print('the convex point is at',convex_point, 'on the x-axis | the parabola intersect the y-axis at',c, '| the determinant is 0');
    elif(d < 0):
        print('Determinant is', d,'and if determinant is smaller than zero, there is no real solution');
    else:
        x_positive = (-b+ math.sqrt(d))/(2*a); # y = 0
        x_negative = (-b- math.sqrt(d))/(2*a); # y = 0
        print('the convex points is at',convex_point, 'on the x-axis |x_positive',x_positive,' |x_negative',x_negative,'| the parabola intersect the y-axis at',c);



except:
    print('try: import math')
def quadratic (a, b, c):
try:
    import matplotlib.pyplot as plt
    import math
    import numpy as np
    d = b**2-4*a*c
    convex_point = -b/(2*a)
    x = np.linspace(-10, 10, 1000);
    y = a**2 + b*x + c
    fig, ax = plt.subplots();
    ax.plot(x, y);
    plt.show()
    if(d == 0):
        convex_point = -b/(2*a) #it is the x-interceptor when det is 0
        print('the convex point is at',convex_point, 'on the x-axis | the parabola intersect the y-axis at',c, '| the determinant is 0');
    elif(d < 0):
        print('Determinant is', d,'and if determinant is smaller than zero, there is no real solution');
    else:
        x_positive = (-b+ math.sqrt(d))/(2*a); # y = 0
        x_negative = (-b- math.sqrt(d))/(2*a); # y = 0
        print('the convex points is at',convex_point, 'on the x-axis |x_positive',x_positive,' |x_negative',x_negative,'| the parabola intersect the y-axis at',c);
except:
    print('try: import math')