Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: aspect ratio control of colorbar Axes fails. #22087

Copy link
Copy link
Open
@efiring

Description

@efiring
Issue body actions

Bug summary

Previously, a colorbar axes could be created with a specified aspect ratio and adjustable "box". Now it leaves whitespace either at the ends or on the sides.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colorbar as mcolorbar

fig, axs = plt.subplots(ncols=3, sharey=True)
for ax, aspect in zip(axs, (20, 40, None)):
    cs = ax.contourf(np.arange(24).reshape((4, 6)), levels=[2, 4, 8, 16], extend="both")
    cax, kw = mcolorbar.make_axes(ax)
    if aspect is not None:
        cax.set_aspect(aspect, anchor=(0.8, 0.5), adjustable='box')
        ax.set_title(f"Cbar aspect is {aspect}")
    else:
        ax.set_title("No cbar aspect")
    cbar = fig.colorbar(cs, cax=cax)
    print(cax.get_aspect(), cax.get_adjustable())
fig.savefig("colorbar_aspect.png")

Actual outcome

colorbar_aspect

Expected outcome

E.g., using mpl 3.4.3:
colorbar_aspect_3-4-3

Additional information

The result is even worse with 3.5.0: the first 2 colorbars in the example are blank except for the triangles.

Operating system

OS/X

Matplotlib Version

3.5.1

Matplotlib Backend

No response

Python version

3.7.12

Jupyter version

No response

Installation

conda

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.