Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ENH: Add tick label alignment parameters to tick_params#30009

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
aydengemz wants to merge3 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromaydengemz:main

Conversation

aydengemz
Copy link

PR summary

This PR adds support for horizontal and vertical alignment of tick labels through thetick_params method, addressing issues#13774 and#20644. The implementation allows users to control the alignment of tick labels directly throughtick_params, making it more consistent with other tick label properties and easier to use.

Changes Made

  1. Added new parameters totick_params:

    • labelhorizontalalignment: Controls the horizontal alignment of tick labels
    • labelverticalalignment: Controls the vertical alignment of tick labels
  2. Added validation for alignment parameters:

    • For x-axis:labelhorizontalalignment accepts 'left', 'center', 'right'
    • For y-axis:labelverticalalignment accepts 'top', 'center', 'bottom', 'baseline', 'center_baseline'
  3. Added tests intest_axis.py to verify the functionality:

    • Testing horizontal and vertical alignment for both x and y axes
    • Testing parameter validation
  4. Updated documentation:

    • Added new parameters totick_params docstring
    • Added documentation inaxis_api.rst
    • Added a "What's New" entry intick_label_alignment.rst

Example Usage

importmatplotlib.pyplotaspltfig,ax=plt.subplots()# Set horizontal alignment for x-axis labelsax.tick_params(axis='x',labelhorizontalalignment='right')# Set vertical alignment for y-axis labelsax.tick_params(axis='y',labelverticalalignment='top')

Why is this change necessary?

Currently, users need to iterate over tick labels to set their alignment, which is less convenient than usingtick_params. This change makes the API more consistent and user-friendly by:

  1. Providing a more intuitive way to set tick label alignment
  2. Making the API more consistent with other tick label properties
  3. Reducing the need for manual iteration over tick labels
  4. Following the principle of least astonishment - if a user specifiesax.tick_params(axis="y", horizontalalignment="left"), they would expect it to apply to the y-axis labels

Implementation Details

The implementation:

  1. Adds the new parameters to the_translate_tick_params method inAxis class
  2. Adds parameter validation inset_tick_params method
  3. Implements the alignment setting in the_apply_params method of theTick class
  4. Maintains consistency with existing tick parameter translation system

PR checklist

  • "closesNo support for horizontal alignment in tick_params? #13774" and "closesadd label alignment to tick_params #20644" are in the body of the PR description
  • New and changed code is tested
    • Addedtest_tick_label_alignment intest_axis.py
  • Plotting related features are demonstrated in an example
    • Added example in PR summary
  • New Features and API Changes are noted with a directive and release note
    • Added new parameters totick_params docstring
    • Added documentation for new parameters
  • Documentation complies with general and docstring guidelines
    • Updated docstrings inaxes/_base.py andaxis.py
    • Added clear descriptions of new parameters

Copy link

@github-actionsgithub-actionsbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join uson gitter for real-time discussion.

For details on testing, writing docs, and our review process, please seethe developer guide

We strive to be a welcoming and open project. Please follow ourCode of Conduct.

Copy link

@evelyn-loevelyn-lo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Review Summary:

The pull request adds two new keyword arguments to tick_params: labelhorizontalalignment and labelverticalalignment, allowing users to control the alignment of tick labels. These are especially useful when axis='x' or axis='y', offering better control over label placement for improved readability.

What’s good:

The new parameters are clearly named and consistent with existing style conventions.

Good documentation: The new parameters are described in both the docstring and usage examples.

The update is minimally invasive and leverages the existing tick_params logic.

Temporary storage of the axis parameter in self._tick_params_axis for use in Axis.set_tick_params is a practical way to enable context-aware behavior.

Suggested Improvements:

Validation logic – While _api.check_in_list validates axis, there's no explicit validation of labelhorizontalalignment and labelverticalalignment. Consider checking that these are valid strings ('center', 'left', 'right', etc.) supported by Text.set_horizontalalignment.

Docstring enhancement – You might clarify that these alignment settings only apply if the axis supports tick labels and that both parameters are passed down to Axis.set_tick_params.

Edge case clarification – For axis='both', it's not clear how or whether both alignments are respected (e.g., is labelhorizontalalignment passed to y-axis?).

@rcomer
Copy link
Member

Thank you for the potential contribution. Unfortunately many tests are failing, including the one you added. I also ran your example code with your branch and got this - the label alignment appears to be unaffected, and we see ticks on the top and right spines that should not be there.
image

Before opening pull requests, you shouldtest changes locally to verify these kind of issue do not come up.

I'm going to mark this as "draft" for now. Please mark it as "ready for review" when you are ready. In the meantime, if you need help, feel free to ask questions here. Or you may prefer to ask them in ourincubator gitter room.

Finally, if you are using AI for any aspect of this, please seehttps://matplotlib.org/devdocs/devel/contribute.html#restrictions-on-generative-ai-usage

@rcomerrcomer marked this pull request as draftMay 5, 2025 11:00
@melissawmmelissawm moved this fromNeeds review toWaiting for author inFirst Time ContributorsMay 22, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@github-actionsgithub-actions[bot]github-actions[bot] left review comments

@evelyn-loevelyn-loevelyn-lo left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Projects
Status: Waiting for author
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

add label alignment to tick_params No support for horizontal alignment in tick_params?
3 participants
@aydengemz@rcomer@evelyn-lo

[8]ページ先頭

©2009-2025 Movatter.jp