以下是我目前的代码:
import statistics
import pandas as pd
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
from datetime import datetime
start_time = datetime.now()
df = pd.read_csv(r"/Users/aaronhuang/Documents/Desktop/ffp/exfileCLEAN2.csv", skiprows=[1])
# replace this with wherever the file is.
magnitudes = df['Magnitude '].values
times = df['Time '].values
average = statistics.mean(magnitudes)
sd = statistics.stdev(magnitudes)
below = sd*3
i = 0
while(i < len(df['Magnitude '])):
if(abs(df['Magnitude '][i]) <= (average - below)):
tim = print(df['Time '][i])
mag = df['Magnitude '][i]
i += 1
window = 2
num = 1
x = tim
y = mag
plt.plot(x, y)
plt.xlabel('Time (units)')
plt.ylabel('Magnitude (units)')
plt.show()
end_time = datetime.now()
print('Duration: {}'.format(end_time - start_time))
目前,它输出以下内容:
/Users/aaronhuang/.conda/envs/EXTTEst/bin/python.
"/Users/aaronhuang/PycharmProjects/EXTTEst/Code sandbox.py"
2456116.494
2456116.535
2456116.576
2456116.624
2456116.673
2456116.714
2456116.799
2456123.527
2456166.634
2456570.526
2456595.515
2457485.722
2457497.93
2457500.674
2457566.874
2457567.877
Traceback (most recent call last):
File "/Users/aaronhuang/PycharmProjects/EXTTEst/Code sandbox.py", line 40, in <module>
plt.plot(x, y)
File "/Users/aaronhuang/.conda/envs/EXTTEst/lib/python3.8/site-
packages/matplotlib/pyplot.py", line 2761, in plot
return gca().plot(
File "/Users/aaronhuang/.conda/envs/EXTTEst/lib/python3.8/site-
packages/matplotlib/axes/_axes.py", line 1646, in plot
lines = [*self._get_lines(*args, data=data, **kwargs)]
File "/Users/aaronhuang/.conda/envs/EXTTEst/lib/python3.8/site-
packages/matplotlib/axes/_base.py", line 216, in __call__
yield from self._plot_args(this, kwargs)
File "/Users/aaronhuang/.conda/envs/EXTTEst/lib/python3.8/site-
packages/matplotlib/axes/_base.py", line 322, in _plot_args
raise ValueError("x, y, and format string must not be None")
ValueError: x, y, and format string must not be None
我不确定如何修复此代码错误。我认为这是由于Tim
和mag
在该函数中被定义。但我不知道如何解决它。
我希望我的代码能够打印一个带有选定点和10个点的图表。如果有人能帮助解决这个错误,那就太好了。谢谢
更改:
致:
相关问题 更多 >
编程相关推荐