注意
转到末尾下载完整的示例代码。
单位处理#
下面的示例显示了对掩码数组的单位转换的支持。
此示例需要basic_units.py

from basic_units import hertz, minutes, secs
import matplotlib.pyplot as plt
import numpy as np
# create masked array
data = (1, 2, 3, 4, 5, 6, 7, 8)
mask = (1, 0, 1, 0, 0, 0, 1, 0)
xsecs = secs * np.ma.MaskedArray(data, mask, float)
fig, (ax1, ax2, ax3) = plt.subplots(nrows=3, sharex=True)
ax1.scatter(xsecs, xsecs)
ax1.yaxis.set_units(secs)
ax2.scatter(xsecs, xsecs, yunits=hertz)
ax3.scatter(xsecs, xsecs, yunits=minutes)
fig.tight_layout()
plt.show()