Skip to content

wcsaxes.coords.set_axeslabel_position not working for y axis #11929

Open

Description

@znusbick

Description

Following the example of the WCS Astropy page but only changing the placement of the axes label, the label was placed incorrectly.

Expected behavior

We expected the label "latitude" to be placed on the right axes only, while longitude was on the bottom.

Actual behavior

The label "latitude" was placed on both the right axis and the top axis.

Steps to Reproduce

from astropy.visualization.wcsaxes import WCSAxes
import matplotlib.pyplot as plt
from matplotlib.transforms import Affine2D
from astropy import units as u


# Set up an affine transformation
transform = Affine2D()
transform.scale(0.01)
transform.translate(40, -30)
transform.rotate(0)  # radians


# Set up metadata dictionary
coord_meta = {}
coord_meta['name'] = 'lon', 'lat'
coord_meta['type'] = 'longitude', 'latitude'
coord_meta['wrap'] = 180, None
coord_meta['unit'] = u.deg, u.deg
coord_meta['format_unit'] = None, None


fig = plt.figure()
ax = WCSAxes(fig, [0.1, 0.1, 0.8, 0.8], aspect='equal',
             transform=transform, coord_meta=coord_meta)
fig.add_axes(ax)
ax.set_xlim(-0.5, 499.5)
ax.set_ylim(-0.5, 399.5)
ax.grid()
ax.coords['lon'].set_axislabel('Longitude')
ax.coords['lat'].set_axislabel('Latitude')


ax.coords['lat'].set_axislabel_position('right')

System Details

Python 3.8.10
Numpy 1.20.2
Astropy 4.2.1
Matplotlib 3.4.2

Activity

  1. github-actions commented on Jul 8, 2021

    @github-actions
    Contributor

    Welcome to Astropy 👋 and thank you for your first issue!

    A project member will respond to you as soon as possible; in the meantime, please double-check the guidelines for submitting issues and make sure you've provided the requested details.

    If you feel that this issue has not been responded to in a timely manner, please leave a comment mentioning our software support engineer @embray, or send a message directly to the development mailing list. If the issue is urgent or sensitive in nature (e.g., a security vulnerability) please send an e-mail directly to the private e-mail [email protected].

  2. astrofrog commented on Jun 19, 2025

    @astrofrog
    Member

    This is a subtle bug in the example you posted - set_axislabel_position does not take e.g. right or left - but one character per axis you want to show it on, r for right`, tfor top, etc. Since the word 'right' contains bothrandt``, it is placed on the right and top. The correct call is:

    ax.coords['lat'].set_axislabel_position('r')
    

    Having said this, I'm surprised we don't error on invalid axis names. I'll investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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