Skip to content

CenteredNorm with halfrange raises exception when passed to imshow #19972

Closed
@marxide

Description

@marxide

Bug report

Bug summary

Passing a CenteredNorm instance with a set halfrange to imshow norm kwarg raises an exception.

Code for reproduction

import matplotlib.pyplot as plt
from matplotlib.colors import CenteredNorm
import numpy as np

data = np.random.random((100, 100))

fig, ax = plt.subplots()
im = ax.imshow(data, norm=CenteredNorm(halfrange=0.2))
fig.colorbar(im)

Actual outcome

AttributeError: 'CenteredNorm' object has no attribute 'vmax'

Expected outcome

An imshow plot with a colorbar clipped to [-0.2, 0.2].

I am currently working around this by using TwoSlopeNorm instead and forcing the two scales to be equal, i.e.

TwoSlopeNorm(0, vmin=-0.2, vmax=0.2)

Matplotlib version

  • Operating system: macOS 11.2.3
  • Matplotlib version: 3.4.1
  • Matplotlib backend: ipykernel.pylab.backend_inline
  • Python version: 3.8.8
  • Jupyter version (if applicable): 3.0.8

Installed with conda using the conda-forge channel.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions