我正在尝试显示力与时间的关系图,并且测量频率可能会发生变化。例如,80 个样本/秒、100 个/秒等。此频率作为“速率”加载。我可以将绘图安排为以任何速率除以秒,但我无法以秒为单位标记 x 轴,只能以样本为单位。我被阻止发布输出图像,但这个测试文件的速率为 80/秒,X 轴标记为 80、160、240、320 等。我怎样才能让它在几秒钟内标记,即 1 , 2, 3, 4 等等?
import numpy as np
import pylab as p
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
x = read_csv_file('test2.csv')
fnum = int(x[0][0]) # run number
rate = int(x[0][1]) # data rate
unit = int(x[0][2]) # 0 = metric
span_r = int(x[0][3]) # calibration setting
span_w = int(x[0][4]) # calibration setting
load = np.loadtxt(x[1], delimiter=',', unpack=True)
xfmt = "1/%d sec" # x axis label
if unit:
span_r = span_r*454
yfmt = "Pounds Force"
else:
span_r = span_r*9.81
yfmt = "Newtons"
fig = plt.figure()
ax = fig.add_subplot(111)
majorLocator = MultipleLocator(rate)
majorFormatter = FormatStrFormatter('%d')
ax.xaxis.set_major_locator(majorLocator)
ax.xaxis.set_major_formatter(majorFormatter)
ax.plot(load * span_w / span_r)
plt.xlabel(xfmt % rate)
plt.ylabel(yfmt)
plt.grid(True)
plt.show()