当我使用matplotlib颜色条时,它似乎采用了中心轴并迫使它左对齐。
我正在添加这样的颜色栏:
def colorbar(scalars, colors):
""" adds a color bar next to the axes """
printDBG('colorbar()')
# Parameters
xy, width, height = _axis_xy_width_height()
orientation = ['vertical', 'horizontal'][0]
TICK_FONTSIZE = 8
#
listed_cmap = scores_to_cmap(scalars, colors)
# Create scalar mappable with cmap
sorted_scalars = sorted(scalars)
sm = plt.cm.ScalarMappable(cmap=listed_cmap)
sm.set_array(sorted_scalars)
# Use mapable object to create the colorbar
COLORBAR_SHRINK = .42 # 1
COLORBAR_PAD = .01 # 1
COLORBAR_ASPECT = np.abs(20 * height / (width)) # 1
printDBG('[df] COLORBAR_ASPECT = %r' % COLORBAR_ASPECT)
cb = plt.colorbar(sm, orientation=orientation, shrink=COLORBAR_SHRINK,
pad=COLORBAR_PAD, aspect=COLORBAR_ASPECT)
# Add the colorbar to the correct label
axis = cb.ax.xaxis if orientation == 'horizontal' else cb.ax.yaxis
position = 'bottom' if orientation == 'horizontal' else 'right'
axis.set_ticks_position(position)
axis.set_ticks([0, .5, 1])
cb.ax.tick_params(labelsize=TICK_FONTSIZE)
我不确定我能做些什么来阻止这种行为。