8000 Contourf Colorbar · Issue #5055 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Contourf Colorbar #5055
Closed
Closed
@lkilcher

Description

@lkilcher

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:

conf

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)

pcol

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0