我正在尝试显示力与时间的关系图,并且测量的频率可以改变。例如,80个样本/秒、100个/秒等。该频率被加载为'rate‘。我可以按任何速率将曲线图划分为秒,但我不能获得以秒为单位的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()发布于 2012-05-23 09:41:21
创建一个时间数组,并使用x轴数据和y轴数据调用plot(),例如pl.plot(x, y)
import pylab as pl
import numpy as np
period = 0.01
data = np.random.rand(1230)
t = np.arange(0, len(data)*period, period)
pl.plot(t, data)
pl.show()发布于 2012-05-23 09:48:01
请参阅How to change the amount of increments in pyplot axis
接下来是:
ax.set_xticks( np.arange(upper-x-bound) )https://stackoverflow.com/questions/10712323
复制相似问题