Closed
Description
The contourf
colorbar
doesn't work as expected.
The following code:
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.colors as mplc
x, y = np.mgrid[0:1:0.01, 0:1:0.01]
r = np.sqrt(x ** 2 + y ** 2)
z = np.sin(6 * np.pi * r)
norm = mplc.Normalize(0, 0.5)
fig0, ax0 = plt.subplots(1, 1, )
cf0 = ax0.contourf(x, y, z, np.arange(-1., 1.001, .01), norm=norm)
cbar0 = plt.colorbar(cf0,)
Produces the following figure:
Compare this with the colorbar of, e.g. a pcolormesh
:
fig2, ax2 = plt.subplots(1, 1)
pc2 = ax2.pcolormesh(x, y, z, norm=norm)
cbar2 = plt.colorbar(pc2)
That's a nice colorbar, and it's what I expect the default behavior to be for contourf
also. Is there a reason the contourf
colorbar behaves this way? I've looked at using the vmin
,vmax
args, and the result is the same. Also, the result is the same for tricontourf
colorbars as well.
Metadata
Metadata
Assignees
Labels
No labels