時間に対する力のプロットを表示しようとしていますが、測定の頻度が変わる可能性があります。たとえば、80サンプル/秒、100/秒など。この周波数は「レート」としてロードされます。任意のレートでプロットを秒で割るように調整できますが、x軸に秒単位でラベルを付けることはできず、サンプルのみです。出力の画像を投稿できませんが、このテストファイルの速度は80 /秒で、X軸には80、160、240、320などのラベルが付いています。秒単位でラベルを付けるにはどうすればよいですか。 、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()