英寸和厘米
该示例说明了使用绘图函数的xunits和yunits参数将默认x和y单位(ax1)覆盖为英寸和厘米的功能。 请注意,应用转换以获取正确单位的数字。
此示例需要basic_units.py

from basic_units import cm, inchimport matplotlib.pyplot as pltimport numpy as npcms = cm * np.arange(0, 10, 2)fig, axs = plt.subplots(2, 2)axs[0, 0].plot(cms, cms)axs[0, 1].plot(cms, cms, xunits=cm, yunits=inch)axs[1, 0].plot(cms, cms, xunits=inch, yunits=cm)axs[1, 0].set_xlim(3, 6) # scalars are interpreted in current unitsaxs[1, 1].plot(cms, cms, xunits=inch, yunits=inch)axs[1, 1].set_xlim(3*cm, 6*cm) # cm are converted to inchesplt.show()
