试图绘制傅立叶罪
from matplotlib import markers
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.cm import get_cmap
plt.rcParams['figure.figsize'] = [9,9]
plt.rcParams.update({'font.size' : 16})
#domain definition
dx = 0.01 #input("input the step size: ")
x = np.pi*np.arange(-1+ float(dx),1+float(dx),float(dx))
n = len(x)
nquart = int(np.floor(n/4))
#hat funtion
f = np.zeros_like(x)
f[nquart : 2*nquart] = (4/n)*np.arange(1,nquart+1)
f[2*nquart:3*nquart] = np.ones(nquart) - (4/n)*np.arange(0,nquart)
#subplot creation
fig,ax = plt.subplots(1)
ax.plot(x,f)
#core fourier series
name = 'accent'
cmap = get_cmap('tab10')
colors = cmap.colors
ax.set_prop_cycle(color = colors)
# sum of values with an array of ones with the same shape and type as a given array.
Ao = np.sum(f*np.ones_like(x))*dx
ffs = Ao/2
A = np.zeros(20)
B = np.zeros(20)
for k in range(20):
#the inner products
A[k] = np.sum(f*np.cos(np.pi*(k+1)*(x/np.pi)))*dx
B[k] = np.sum(f*np.sin(np.pi*(k+1)*(x/np.pi)))*dx
ffs = ffs + A[k]*np.cos((k+1)*np.pi*(x/np.pi)) + B[k]*np.sin((k+1)*np.pi*(x/np.pi))
ax.plot(x,ffs,markers = 'o',LineWidth = 1.5)
plt.show()
运行代码时,我会收到错误 attributeError:'line2d'对象没有属性标记,'lineWidth' 如果我不使用标记和线宽,则代码运行,但预期的结果不是我想要的 我得到了大约15个图,但这不是我想要的色彩样式也没有应用
from matplotlib import markers
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.cm import get_cmap
plt.rcParams['figure.figsize'] = [9,9]
plt.rcParams.update({'font.size' : 16})
#domain definition
dx = 0.01 #input("input the step size: ")
x = np.pi*np.arange(-1+ float(dx),1+float(dx),float(dx))
n = len(x)
nquart = int(np.floor(n/4))
#hat funtion
f = np.zeros_like(x)
f[nquart : 2*nquart] = (4/n)*np.arange(1,nquart+1)
f[2*nquart:3*nquart] = np.ones(nquart) - (4/n)*np.arange(0,nquart)
#subplot creation
fig,ax = plt.subplots(1)
ax.plot(x,f)
#core fourier series
name = 'accent'
cmap = get_cmap('tab10')
colors = cmap.colors
ax.set_prop_cycle(color = colors)
# sum of values with an array of ones with the same shape and type as a given array.
Ao = np.sum(f*np.ones_like(x))*dx
ffs = Ao/2
A = np.zeros(20)
B = np.zeros(20)
for k in range(20):
#the inner products
A[k] = np.sum(f*np.cos(np.pi*(k+1)*(x/np.pi)))*dx
B[k] = np.sum(f*np.sin(np.pi*(k+1)*(x/np.pi)))*dx
ffs = ffs + A[k]*np.cos((k+1)*np.pi*(x/np.pi)) + B[k]*np.sin((k+1)*np.pi*(x/np.pi))
ax.plot(x,ffs,markers = 'o',LineWidth = 1.5)
plt.show()
when running the code i get an error AttributeError: 'Line2D' object has no property'markers ,'LineWidth'
if i do not use the markers and LineWidth the code runs but the expected outcome is not what i wanted
i am getting around 15 graphs but that is not what i wanted the color style is also not getting applied
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是因为它应该是
标记
和line> lineWidth
:随着这些更改,并进行
plt.showshow ()
脱离循环:...我们获得:

That's because it should be
marker
andlinewidth
:With those changes, and taking
plt.show()
out of the loop:...we obtain:
