8000 [Bug]: colorbar for `matshow` taller than plot unless using `fignum=0` · Issue #22972 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
[Bug]: colorbar for matshow taller than plot unless using fignum=0 #22972
Closed
@phil-blain

Description

@phil-blain

Bug summary

When using plt.colorbar along with plt.matshow, the colorbar is taller than the plot. If I use plt.matshow(A, fig=0), then it is the same height as the plot.

Code for reproduction

# Basically https://matplotlib.org/stable/gallery/images_contours_and_fields/matshow.html#sphx-glr-gallery-images-contours-and-fields-matshow-py with a colorbar added

import matplotlib.pyplot as plt
import numpy as np

# a 2D array with linearly increasing values on the diagonal
a = np.diag(range(15))

plt.matshow(a) # this triggers the bug
# plt.matshow(a, fignum=None) # this too
# plt.matshow(a, fignum=1) # this too

# plt.matshow(a, fignum=False) # this triggers the expected outcome
# plt.matshow(a, fignum=0) # this too

plt.colorbar()
plt.show()

Actual outcome

Figure_1

Expected outcome

Figure_2

Additional information

No response

Operating system

Ubuntu 20.04

Matplotlib Version

3.5.2

Matplotlib Backend

QtAgg

Python version

Python 3.10.4

Jupyter version

none involved

Installation

conda

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