简体   繁体   English

如何使用时间间隔设置xaxis,例如使用matplotlib设置15分钟

[英]how to set the xaxis in time interval, say 15min using matplotlib

How to set the xaxis in time interval 15minutes as: 如何以15分钟的时间间隔将xaxis设置为:

'08:00', '08:15', '08:30', '08:45', '09:00', '09:15', '09:30', '09:45', '10:00','10:15', '10:30', '10:45','11:00'

So each one is a label in xaxis. 因此,每个都是xaxis中的标签。

data is as follows: 数据如下:

data = [[0,1],[08:18,09:16],[10:18,10:52]]

x1 = data[:][1]

x2 = data[:][2]

y = data[:][0]

I want to use plot function to plot with data as above: 我想使用plot函数以上述方式绘制数据:

plt.plot(data[:][1], y,
         data[:][2], y)

After plotting, there should have two lines on the map. 绘制后,地图上应该有两条线。 And the labels are in time interval of 15min. 标签间隔为15分钟。

  1. The given data is not valid in Python. 给定的data在Python中无效。 It should be like [["0","1"],["08:18","09:16"]] . 它应该像[["0","1"],["08:18","09:16"]]

  2. Write a function to translate the time intervals into real number. 编写一个将时间间隔转换为实数的函数。 (For understandablity to you, the code is not that pythonic.) (为了便于您理解,代码不是那种pythonic。)

     def time_to_num(time_str): time_str = time_str.split(':') #check if time_str is valid here, then: num = 0 num = int(time_str[0]) if len(time_str) == 2: num += int(time_str[1])/60.0 return num 
  3. Make it like x1 = [time_to_num(item[1]) for item in data] 使它像x1 = [time_to_num(item[1]) for item in data]

  4. Set the X axis lable as time interval with something like: 将X轴标签设置为时间间隔,例如:

     #fig = matplotlib.plot... fig.set_xticks([0, 0.25, 0.5, 0.75, 1, 1.25]) fig.set_xticklabels(['0:00', '0:15', '0:30', '0:45', '1:00', '1:15']) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不使用最小/最大/总和或平均值的情况下将 dataframe 的日期时间值分配给下一个 15 分钟时间步长? - How to asign Datetime values of a dataframe to the next 15min Timestep without using min/max/sum or mean? 如何实现“如果错误等待 15 分钟然后继续”? - how to implement an "If error wait for 15min then continue"? Python:将时间戳四舍五入到 15 分钟间隔,附加到 df 但缺少小时、分钟和秒,dtype:datetime64[ns] - Python: Rounding timstamp to 15min interval, appended to a df but missing hours, minutes and seconds, dtype: datetime64[ns] 推断数据帧以计算 15 分钟和 30 分钟的平均值 - Extrapolating dataframes to calculate 15min and 30min averages 每隔10分钟在matplotlib中绘制时间 - Plotting time in matplotlib for every 10 min interval NumPy数组15分钟值-每小时平均值 - Numpy array 15min values - hourly mean values Matplotlib 在 xaxis 上设置频率 - Matplotlib to set the frequency on xaxis Python Pandas 对数据点之间的平均值进行上采样(15 分钟到 1 分钟) - Python Pandas Upsampling on average values between data points (15min to 1min) 如何使用python中的Dash Plotly间隔更新xaxis和yaxis名称? - How to update xaxis and yaxis name on interval using Dash Plotly in python? 将时间戳汇总到15分钟(以小时为单位),并找到熊猫中多列的总和,平均和最大值 - Aggregate to 15min based timestamp to hour and find sum, avg and max for multiple columns in pandas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM