Skip to content

[Bug]: Labels don't get wrapped when set_yticks() is used in subplots #28358

@soogui

Description

@soogui

Bug summary

When plotting bar charts in subplots with very long labels, the option of wrapping text only works on the first plotted subplot, despite passing wrap=True to set_yticks() in both cases.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

long_text_label = 'very long category label i want to wrap'
labels = [f"{long_text_label}_{i}" for i in range(5)]
values = np.arange(1, 6)

fig, axes = plt.subplots(1, 2)

axes[0].barh(np.arange(len(labels)), values)
axes[0].set_yticks(np.arange(len(labels)), labels=labels, wrap=True)

axes[1].barh(np.arange(len(labels)), values)
axes[1].set_yticks(np.arange(len(labels)), labels=labels, wrap=True)

Actual outcome

output

Expected outcome

The label text on the y axis should appear wrapped on both subplots

Additional information

No response

Operating system

macOS 14.4 (23E214)

Matplotlib Version

3.8.3

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

Python 3.11.8

Jupyter version

4.2.0

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions