Closed
Description
Bug report
Bug summary
Coming from this stackoverflow question I was wondering if it would be useful to allow the limits of the colorbar axes to be used for restricting the range of colors to be shown in the colorbar. I.e.
colorbar.ax.set_ylim(-2, 8)
Code for reproduction
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
x = np.linspace(-2,8)
mima = np.max((np.abs(x.min()), np.abs(x.max())))
norm = mcolors.Normalize(-mima, +mima)
sc = plt.scatter(x,x, c=x, cmap = 'seismic', norm=norm)
cb = plt.colorbar(sc, orientation="horizontal")
cb.ax.set_xlim(x.min(), x.max())
plt.margins(x=0)
plt.savefig("test.png", bbox_inches="tight")
plt.show()
Actual outcome
Expected outcome