0
如何创建一个紧凑的水平尺,例如温度温度计,使用Matplotlib的压力气压计。量表的尺度将被分割成范围;每个范围表示高 - 高。低和低 - 低和一个指针读取值?是否有可能在matplotlib中创建这样的测量仪?紧凑的水平尺Matplotlib
如何创建一个紧凑的水平尺,例如温度温度计,使用Matplotlib的压力气压计。量表的尺度将被分割成范围;每个范围表示高 - 高。低和低 - 低和一个指针读取值?是否有可能在matplotlib中创建这样的测量仪?紧凑的水平尺Matplotlib
您可以使用一个颜色条。
例如:
import matplotlib.pyplot as plt
import matplotlib as mpl
fig = plt.figure(figsize=(8, 2))
ax = fig.add_axes([0.1, 0.4, 0.8, 0.2])
bounds = [-20, -10, 0, 10, 20]
labels = ('low-low', 'low', 'high', 'high-high')
cmap = mpl.cm.coolwarm
norm = mpl.colors.Normalize(vmin=bounds[0], vmax=bounds[-1])
cb = mpl.colorbar.ColorbarBase(
ax,
cmap=cmap,
norm=norm,
orientation='horizontal',
boundaries=bounds,
label='temperature (degrees celcius)',
)
for i, label in enumerate(labels):
xpos = float((2*i + 1))/(2*len(labels))
ax.annotate(label, xy=(xpos, 0.5), xycoords='axes fraction', ha='center', va='center')
plt.show()
将会产生这样的:
欲了解更多信息请参阅these examples in the matplotlib docs。
太棒了。谢谢。如何将该值标记为缩放指针?说,如果我的温度是5摄氏度。 –