[英]VALUE ERROR: x, y, and format string must not be None. (error while plotting hysteresis loop)
With the low cycle fatigue data, I'm trying to plot the Hysteresis loop.使用低周疲劳数据,我试图绘制磁滞回线。 But I'm getting the following error:
但我收到以下错误:
[ -52.18297297 -45.58565338 16.9913185 ... -354.53630032 -295.50857248
-155.42088911]
[-0.01229182 -0.00891753 0.02256744 ... -0.33507242 -0.31283728
-0.24790212]
Traceback (most recent call last):
File "f:\I2M\LCF\Ep1_camp4_P4_TTH650 06-9-21 11 01 24\ep1_camp4_P4.py", line 16, in <module>
plt.plot(strain, Sigma, color = 'k')
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-
packages\matplotlib\pyplot.py", line 2840, in plot
return gca().plot(
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-
packages\matplotlib\axes\_axes.py", line 1743, in plot
lines = [*self._get_lines(*args, data=data, **kwargs)]
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-
packages\matplotlib\axes\_base.py", line 273, in __call__
yield from self._plot_args(this, kwargs)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-
packages\matplotlib\axes\_base.py", line 379, in _plot_args
raise ValueError("x, y, and format string must not be None")
ValueError: x, y, and format string must not be None
And here is my code:这是我的代码:
import matplotlib.pyplot as plt
import numpy as np
plt.style.use(['science','no-latex'])
x = np.loadtxt('F:\\I2M\\LCF\\Ep1_camp4_P4_TTH650 06-9-21 11 01 24\\data_1.csv',unpack = True,
skiprows = 2, usecols = 2, delimiter = ',')
y = np.loadtxt('F:\\I2M\\LCF\\Ep1_camp4_P4_TTH650 06-9-21 11 01 24\\data_1.csv',unpack = True,
skiprows = 2, usecols = 3, delimiter = ',')
stress = (x*1000)/28.27 #N/mm^2 = MPa
length = len(stress)
length = len(y)
plt.figure(figsize=(5, 5))
Sigma = print(stress[0:length:10]) #stress
strain = print(y[0:length:10])
plt.plot(strain, Sigma, color = 'k')
plt.show()
Data contains many rows.数据包含许多行。 So I used some commands to access only particular values from the row
所以我使用了一些命令来只访问行中的特定值
Your problem is here你的问题在这里
Sigma = print(stress[0:length:10]) #stress
strain = print(y[0:length:10])
what you want plausibly is to sample every 10th data point, but what you get is … nothing or, from the point of view of Python: None
, so that later your stack trace informs you that x, y, and format string must not be None
.你想要的似乎是每 10 个数据点采样一次,但你得到的是......没有或者,从 Python 的角度来看:
None
,以便稍后你的堆栈跟踪通知你x, y, and format string must not be None
。
Why this happens, and how you solve the problem?为什么会发生这种情况,您如何解决问题?
When you make an assignment, the value of the expression on the right is saved and you can use the name on the left to use it later, so you save, eg, the value returned by print(y[0:length:10])
to use it later under the name strain
, but print()
is used for its side effects (ie, showing a bunch of characters on your terminal) and the value that is returned in these cases is by default None
, not what was shown on your terminal.赋值的时候,右边的表达式的值被保存了,你可以用左边的名字稍后使用,所以你保存,例如,
print(y[0:length:10])
返回的值print(y[0:length:10])
稍后在名称strain
下使用它,但print()
用于其副作用(即,在终端上显示一堆字符)并且在这些情况下返回的值默认为None
,而不是显示的值在您的终端上。
If I have understood your intentions, you should omit the two lines above and just use如果我理解你的意图,你应该省略上面的两行,只使用
plt.plot(x[0:length:10], y[0:length:10], color='k')
A side note, you have旁注,你有
length = len(stress)
length = len(y)
but you read them from the same file, one assignment should be enough…但是你从同一个文件中读取它们,一个作业就足够了……
PS聚苯乙烯
x, y = np.loadtxt('…\\data_1.csv', unpack=1, skiprows=2, usecols=[2,3], delimiter=',')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.