Thanks to visit codestin.com
Credit goes to github.com

Skip to content

No link to shared axes for Axis.set_units #10304

Closed
@duncanmmacleod

Description

@duncanmmacleod

Bug report

Bug summary

The Axis.set_units method does not emit to linked axes in the same way that Axes.set_xlim does (by default).

Code for reproduction

from matplotlib import pyplot
from astropy import units
from astropy.visualization import quantity_support

data = units.Quantity([1, 2, 3, 4, 5], 'm')

with quantity_support():
    fig = pyplot.figure()
    ax1 = fig.add_subplot(2, 1, 1)
    ax2 = fig.add_subplot(2, 1, 2, sharey=ax1)
    ax1.plot(data)
    ax2.plot(data)
    print('After first plot:')
    print(ax1.yaxis.get_units())
    print(ax2.yaxis.get_units())
    ax1.yaxis.set_units(units.cm)
    print('After manual set_units():')
    print(ax1.yaxis.get_units())
    print(ax2.yaxis.get_units())

Actual outcome

After first plot:
m
m
After manual set_units():
m
cm

Expected outcome

If set_units was linked to all shared axes, I would expect the call out to ax1.yaxis.set_units to also operate on ax2.

This is probably best exposed via new set_xunits and set_yunits methods for the Axes object, that include an emit=True keyword to use self._shared_x_axes.get_siblings in the same way as Axes.set_{x,y}lim.

Matplotlib version

  • Operating system: macOS 10.13.2
  • Matplotlib version: 2.1.1
  • Matplotlib backend (print(matplotlib.get_backend())): 'agg'
  • Python version: 2.7.14
  • Jupyter version (if applicable):
  • Other libraries: astropy 2.0.2

all installed with macports.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions