[英]Plot graph in Python
import numpy as np将 numpy 导入为 np
import pandas as pd将熊猫导入为 pd
import matplotlib.pyplot as plt将 matplotlib.pyplot 导入为 plt
''' '''
K = 1 K = 1
Rmv = 26 Rmv = 26
SigS = 111.7信号强度 = 111.7
M = 2.050 M = 2.050
N = 2 N = 2
SigD = (-249.4)信号强度 = (-249.4)
def Mittelspannung(): def Mittelspannung():
result = []
Z = []
SigM = []
for i in range(1,31):
output = 1 - pow((((i-1)*1/14.5)-1),2)
result.append(output)
#print(output)
for value in range(0,15):
C4 = (Rmv) - (result[value]) * (Rmv)
Z.append(C4)
print(C4)
for value in range(15,30):
B11 = (SigD) - (result[value]) * (SigD)
Z.append(B11)
print(B11)
for x in range(0,30):
SigMean = ((SigS**M * (1-(Z[x] + SigS)**N/(Rmv + SigS)**N))**(1/M)) / K
SigM.append(SigMean)
return SigM
print(Mittelspannung())打印(Mittelspannung())
''' '''
I'm trying to plot the graph between 'Z' and 'SigM'.我正在尝试绘制“Z”和“SigM”之间的图表。 I'm getting an error.我收到一个错误。 Could anyone please help in plotting the graph.任何人都可以帮助绘制图表。
You should create a list Z
in which you are going to append the Z values computed at each iteration, like this:您应该创建一个列表Z
,您将在其中附加每次迭代计算的 Z 值,如下所示:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
K = 1
Rmv = 26
SigS = 111.7
M = 2.050
N = 2
SigD = (-249.4)
def Mittelspannung():
result = []
Y = []
SigM = []
Z = []
for i in range(1,31):
output = 1 - pow((((i-1)*1/14.5)-1),2)
Z.append(Rmv - (output*Rmv))
result.append(output)
for value in range(0,15):
C4 = (Rmv) - (result[value]) * (Rmv)
Y.append(C4)
for value in range(15,30):
B11 = (SigD) - (result[value]) * (SigD)
Y.append(B11)
for x in range(0,30):
SigMean = ((SigS**M * (1-(Z[x] + SigS)**N/(Rmv + SigS)**N))**(1/M)) / K
SigM.append(SigMean)
return Z, SigM
Z, SigM = Mittelspannung()
plt.figure()
plt.plot(Z, SigM)
You didn't define Z in the function call.您没有在函数调用中定义 Z 。 Depending on what tool your using, you should be able to see that in the error message, something like "Z is being used before initializing".根据您使用的工具,您应该能够在错误消息中看到“在初始化之前正在使用 Z”之类的内容。
Z, SigM = Mittelspannung()
plt.figure()
plt.plot(Z, SigM)
this code will show you the error此代码将向您显示错误
#error #错误
----> 1 Z, SigM = Mittelspannung()
2 plt.figure()
3 plt.plot(Z, SigM)
ValueError: too many values to unpack (expected 2) ValueError:要解包的值太多(预期为 2)
// Try this one //试试这个
SigM = Mittelspannung()
plt.figure()
plt.plot(SigM)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.