微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何仅绘制 6 小时数据集立方体虹膜中的小时数据?

如何解决如何仅绘制 6 小时数据集立方体虹膜中的小时数据?

到目前为止,我绘制图形的代码如下:

iplt.plot(pressure_no1,color='black')
plt.xlabel('Time / hour of day')
plt.ylabel('Atmospheric pressure / kPa')
iplt.show()

这是一个 6 小时的立方体(虽然是二维的)数据集,有 420 个数据点。我只需要绘制数据点 hr=0,hr=1 hr=2,hr=3,hr=4,hr=5 并且一小时之间没有。

可以像下面这样工作吗?

pressure_no1_hrs = pressure_no1.coord('hour'==int).points
plt.plot(pressure_no1_hrs)

Image of graph with all data points and start of the time coordinates Image of last lot of time coordinates

解决方法

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd


measures = np.random.normal(size=(360,))
timepoints = np.arange(start=0,stop=360)


df = pd.DataFrame({'measure': measures,'timepoint': timepoints})

is_hour = df.loc[:,'timepoint'] % 60 == 0  # <- Only select full hour

plt.plot(df.loc[is_hour,'measure'])
plt.xlabel("Time [min]")
plt.ylabel("Atmospheric pressure / kPa")
plt.show()
,

对于特定于 Iris 的解决方案,您可以使用 PartialDateTime

import iris
import iris.quickplot as qplt
import numpy as np
import matplotlib.pyplot as plt

measures = np.random.normal(size=(360,stop=360)

cube = iris.cube.Cube(measures,long_name='atmospheric_pressure',units='kPa')
time_coord = iris.coords.DimCoord(
    timepoints,units='minutes since 2020-07-01 00:00',standard_name='time')
cube.add_dim_coord(time_coord,0)

subcube = cube.extract(iris.Constraint(time=iris.time.PartialDateTime(minute=0)))

qplt.plot(cube,label='All data')
qplt.plot(subcube,label='Hourly data')

plt.legend()

plt.show()

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。