Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No link to shared axes for Axis.set_units #10304

Closed
duncanmmacleod opened this issue Jan 23, 2018 · 3 comments · Fixed by #18308
Closed

No link to shared axes for Axis.set_units #10304

duncanmmacleod opened this issue Jan 23, 2018 · 3 comments · Fixed by #18308

Comments

@duncanmmacleod
Copy link
Contributor

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.

@jklymak jklymak added this to the v3.0 milestone Jan 23, 2018
@jklymak
Copy link
Member

jklymak commented Jan 23, 2018

Units support are a bit inconsistent. Does astropy regularly use them for plotting? It'd be good if a dev who uses them regularly could help w/ them in Matplotlib. We have some old examples JPL wrote, which if I recall correctly don't quite work if you extend them at all.

See #9713

@duncanmmacleod
Copy link
Contributor Author

@jklymak, astropy provides a ConversionInterface that integrates its own units package with the matplotlib infrastructure, but I have no idea if its widely used (I have only just started playing with it). I am happy to try and extend the unit infrastructure as I go along, which might not amount to much.

@jklymak
Copy link
Member

jklymak commented Jan 23, 2018

It seems the Matplotlib should consider using a minimal units system for testing. We have one in examples/units/basic_units.py, but it doesn't do sensible things if you start mixing units from what I can tell. What happens if you do

ax.xaxis.set_units(cm)
ax.plot(x * cm, x)
ax.xaxis.set_units(m)
plt.show()

I'd expect to see things plotted in meters, but the conversion happens when plot is called, so it never knows about the m units. What happens if we subsequently do

ax.plot(datetime(2018,1,1))

on that axis?

This'll all take a bit of thought to do correctly, and maybe when JPL originally did this, they put the thought in, but subsequently its no longer as cohesive.

@tacaswell tacaswell modified the milestones: v3.0, v3.1 Aug 11, 2018
@tacaswell tacaswell modified the milestones: v3.1.0, v3.2.0 Mar 18, 2019
@timhoffm timhoffm modified the milestones: v3.2.0, v3.3.0 Aug 15, 2019
@QuLogic QuLogic modified the milestones: v3.3.0, v3.4.0 May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants