我的Python文件有问题

时间:2015-12-20 15:33:08

标签: python matplotlib plot

根据控制台的错误是:

plt.grafica() AttributeError:'module'对象没有属性'gráfica'

如果你能帮助我,请提供完整的代码。

import matplotlib as plt
from sympy.abc import k,x
from math import pi
from sympy import cos

A=float(input("Introduzca una Amplitud: ")) 
a=int(input("Introduzca los armonicos que desea calcular: "))
Td=float(input("Introduzca el valor del retraso: ")) 

funcion = (((1/pi)*A) + ((0.5) * (cos(2*pi*(x-Td)))))
serie = (((pow(-1, k+1)) / (pow(4*k,2) -1)) * (cos(4*k*pi*(x-Td))))


for p in range (2,a-2):
    funcion = funcion + serie.subs(k, p)


x1 = funcion
y1 = cos(x)
x2 = serie
y2 = cos(x)

ylim = [-A,A]
xlim =[-1.5,1.5]

plt.figura()

plt.plot(x1, y1, 'b--', linewidth = 2, label = 'funcion')
plt.hold(True)
plt.plot(x2, y2, 'r^', linewidth = 2, label = 'serie')
plt.grid(True)
plt.grid(color = '0.5', linestyle = '--', linewidth = 0.8)
plt.title('Tarea 2',fontsize = 28, color = '0.75', verticalalignment =        'baseline', horizontalalignment = 'center')

plt.show() # Se muestra por la pantalla la grafica de la funcion

1 个答案:

答案 0 :(得分:1)

导入错误,您需要matplotlib.pyplot

import matplotlib.pyplot as plt

这也不是图形plt.figure()

相关问题