要在 matplotlib 中构建不带绘图的颜色条,我们可以采取以下步骤。
设置图形大小并调整子图之间和周围的填充。
创建一个图形和一组子图。
调整子图布局参数。
将四元数归一化。返回四元数的范数。
获取具有基本颜色条和水平方向的颜色条实例(cb) 。
要显示图形,请使用Show()方法。
importmatplotlib.pyplotas plt import matplotlib as mpl # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create a figure and a set of subplots fig, ax = plt.subplots() # Adjust the subplot layout parameter fig.subplots_adjust(bottom=0.5) # Normalize norm = mpl.colors.Normalize(vmin=5, vmax=10) # Get the colorbar instance cb = mpl.colorbar.ColorbarBase(ax, cmap=mpl.cm.cool, norm=norm, orientation='horizontal') # Display the plot plt.show()输出结果
它将产生以下输出 -