备注
Go to the end to download the full example code.
弧度刻度#
使用 basic_units 模拟示例包中的弧度进行绘图.
此示例显示了单位类别如何确定刻度定位,格式和轴标签.
此示例需要 basic_units.py
Traceback (most recent call last):
File "/mnt/hgfs/github/matplotlib-3.10.0/galleries/examples/units/radian_demo.py", line 26, in <module>
axs[0].plot(x, cos(x), xunits=radians)
^^^^^^
File "/mnt/hgfs/github/matplotlib-3.10.0/galleries/examples/units/basic_units.py", line 382, in cos
return [math.cos(val.convert_to(radians).get_value()) for val in x]
^^^^^^^^^^^^^^
AttributeError: 'numpy.float64' object has no attribute 'convert_to'
from basic_units import cos, degrees, radians
import matplotlib.pyplot as plt
import numpy as np
x = [val*radians for val in np.arange(0, 15, 0.01)]
fig, axs = plt.subplots(2)
axs[0].plot(x, cos(x), xunits=radians)
axs[1].plot(x, cos(x), xunits=degrees)
fig.tight_layout()
plt.show()