Skip to content

[Bug]: Inconsistent y-axis unit label with plot/scatter #23416

Open
@dstansby

Description

@dstansby

Bug summary

When manually setting the units of an axis using set_units, a plot will show an axis label, but a scatter won't.

The example needs to be run in examples/units to have access to the basic_units.py file.

Code for reproduction

from basic_units import cm
import matplotlib.pyplot as plt
import numpy as np

cms = cm * np.arange(0, 10, 2)

fig, axs = plt.subplots(1, 2, tight_layout=True)

# Does create a y-axis label
axs[0].yaxis.set_units(cm)
axs[0].plot(np.arange(5), cms)

# Does not create a y-axis label
axs[1].yaxis.set_units(cm)
axs[1].scatter(np.arange(5), cms)

plt.show()

Actual outcome

broken

Expected outcome

When the units aren't explicitly set (commenting out set_units()), the output is as expected with both labels:
good

Additional information

No response

Operating system

No response

Matplotlib Version

3.6.0.dev2669+gdc163ca442.d20220712

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

git checkout

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions