【发布时间】:2018-12-19 07:52:21
【问题描述】:
我正在使用以下代码从我的两列原始数据(x=time,y=|float data|)中绘制一条曲线。它绘制的图形是一个粗糙的边缘图。是否有可能对这些数据进行平滑处理?我附上代码、数据和曲线。
from datetime import datetime
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates
from matplotlib import style
# changing matplotlib the default style
matplotlib.style.use('ggplot')
#one of {'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'}
plt.rcParams['lines.linewidth']=1
plt.rcParams['axes.facecolor']='.3'
plt.rcParams['xtick.color']='b'
plt.rcParams['ytick.color']='r'
x,y= np.loadtxt('MaxMin.txt', dtype=str, unpack=True)
x = np.array([datetime.strptime(i, "%H:%M:%S.%f") for i in x])
y = y.astype(float)
# naming the x axis
plt.xlabel('<------Clock-Time(HH:MM:SS)------>')
# naming the y axis
plt.ylabel('Acceleration (m/sq.sec)')
# giving a title to my graph
plt.title('Sample graph!')
# plotting the points
plt.plot(x, y)
# beautify the x-labels
plt.gcf().autofmt_xdate()
#Custom Format
loc = matplotlib.dates.MicrosecondLocator(1000000)
plt.gca().xaxis.set_major_locator(loc)
plt.gca().xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%H:%M:%S'))
# function to show the plot
plt.show()
我搜索过类似的主题,但它们使用的数学概念让我无法理解。所以我无法确定对我的数据究竟需要做什么。
我还提供了示例数据文件,以便您可以在最后重新构建它。
PS。即使在使用后,我也无法将图表中的线条颜色从默认红色更改
plt.rcParams['lines.color']='g'
虽然在这种情况下这是一个小问题。
**请使用我的代码和数据,看看你的建议是否真的有效,如果可能的话,发布输出图。我是 python 的初学者。所以还不完全熟悉其他人非常明显的东西。 **
【问题讨论】:
-
数据看起来不按时间顺序排列,因此您可能不需要在点之间添加额外的线条。在绘图之前按时间顺序对输入数据进行排序。
-
它是基于时间的按时间顺序排序的,否则无法排序。我想知道是否可以使用某种过滤器对其进行平滑处理,或者是否需要应用 SVM 等机器学习工具。因为这些是我看到的术语,但不知道什么对这个数据集有好处。
-
您希望看到什么输出?就目前而言,这个问题非常广泛,尽管这个例子的完整性非常值得称赞。
标签: python filter fft curve smoothing