8000 Units handling different with plot than other functions... · Issue #9713 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Units handling different with plot than other functions... #9713
Open
@jklymak

Description

@jklymak

Bug report

Units always get reset for plot whereas scatter (for instance) doesn't reset units...

Code for reproduction

This leads to inconsistent behaviour between plot and (for instance) scatter:

import matplotlib
matplotlib.use('Qt5Agg')
import numpy as np
import matplotlib.pyplot as plt
from basic_units import secs, hertz, minutes

# create masked array
data = (1, 2, 3, 4, 5, 6, 7, 8)
mask = (1, 0, 1, 0, 0, 0, 1, 0)
xsecs = secs * np.ma.MaskedArray(data, mask, float)
xsecs2 = secs * np.ma.MaskedArray(np.array(data)+2, mask, float)
fig, (ax0, ax1, ax2, ax3) = plt.subplots(4, 1)

ax0.plot(xsecs, xsecs2, yunits=secs)

ax1.plot(xsecs, xsecs2, yunits=secs)
ax1.plot(xsecs, xsecs, yunits=minutes)

ax2.scatter(xsecs, xsecs2, yunits=secs)

ax3.scatter(xsecs, xsecs2, yunits=secs)
ax3.scatter(xsecs, xsecs, yunits=minutes)

plt.setp([ax0, ax1, ax2, ax3], 'ylim', [0, 12])
plt.show()

Actual outcome

  1. Neither case makes much sense
  2. The cases don't make sense in different ways.

figure_1

Expected outcome

The fact that neither case makes sense is maybe the fault of basic_units.py. But that asside, the fact that they are wrong in different ways is because plot and scatter handle units differently.

There is a discussion here: #9705 (comment) but basically plot updates units no matter if the units have already been set for an axis, whereas scatter and other functions do not updat ethe units if they have already been set.

This was the fundamental cause of the error in #9705 not being caught.

I think plot should be made consistent w/ the other plotting functions and only update the units if they have not been set.

I think future unit handlers should decide what to do if the new axis has different units.

Matplotlib version

  • Operating system:
  • Matplotlib version:
  • Matplotlib backend (print(matplotlib.get_backend())):
  • Python version:
  • Jupyter version (if applicable):
  • Other libraries:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0