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

Skip to content

Add x-coordinate Control for Axes Title Positioning (Issue #7946) #27533

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

Closed
wants to merge 4 commits into from
Closed

Add x-coordinate Control for Axes Title Positioning (Issue #7946) #27533

wants to merge 4 commits into from

Conversation

MrAlexanderHwang
Copy link

Description

This PR introduces a new feature that allows users to control the x-coordinate of Axes titles in Matplotlib. Prior to this change, the title's horizontal position was automatically determined, which could sometimes lead to overlap with other elements on the Axes. This enhancement is a response to Issue #7946, where there was a need for greater control over the title positioning.

Changes Made

  1. Modified _axes.py:

    • Updated the set_title method to include a new parameter x=None, allowing users to specify the horizontal position of the Axes title (File: lib/matplotlib/axes/_axes.py).
  2. Documentation and Configuration Updates:

    • Added documentation for the new x parameter in the set_title method, explaining its default behavior and usage (File: lib/matplotlib/axes/_axes.py)【58†source】.
    • Included the axes.titlex setting in matplotlibrc and classic.mplstyle, with a default value of None to maintain backward compatibility (Files: lib/matplotlib/mpl-data/matplotlibrc, lib/matplotlib/mpl-data/stylelib/classic.mplstyle).
  3. Configuration Validation:

    • Updated rcsetup.py to validate the axes.titlex parameter (File: lib/matplotlib/rcsetup.py).
  4. Testing:

    • Modified tests in test_axes.py and test_text.py to ensure the new functionality works as expected and does not affect other features (Files: lib/matplotlib/tests/test_axes.py, lib/matplotlib/tests/test_text.py).

This is my attempt at contribution to an open source project. I would appreciate a review of the code changes! Thank you.

Copy link

@github-actions github-actions bot 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 us on gitter for real-time discussion.

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

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

@MrAlexanderHwang MrAlexanderHwang marked this pull request as draft December 16, 2023 18:32
@oscargus
Copy link
Member

Thank you for this!

There are actually three titles predefined: left, center, and right. If something like this is introduced, I think it only should affect one of them, most likely the center title. Hence, I believe that the default value of x should be 0.5 and that _left_title and _right_title should keep their previous values.

Also, there is an additional docker-file that should not be there.

@rcomer
Copy link
Member

rcomer commented Dec 18, 2023

I am a bit confused by this PR. The referenced issue discusses set_ylabel, but the PR modifies set_title @MrAlexanderHwang did you mean to reference a different issue or am I missing something?

@timhoffm
Copy link
Member

TL;DR: I don't think there is anything to do here for set_title.

x is already part of the **kwargs that you can pass to set_title, and in the current master branch, this works:

grafik

There is no need to reimplement this explicitly. Furthermore, I don't think we want/need a titlex rcparam. The technical problem is that there are three titles (https://matplotlib.org/stable/gallery/text_labels_and_annotations/titles_demo.html). A single rcparam does not fit to that. It would either just operate one one (which also needs separate logic and explanation) or if set, it would superimpose the different titles.
IMHO therefore, it's simplest to not try to cover that in rcparams. This should be rare enough.

@MrAlexanderHwang
Copy link
Author

Sorry you are corret, will amend and notify once on I correctly work on set_ylabel.

@jklymak
Copy link
Member

jklymak commented Dec 18, 2023

I'd suggest closing and opening a new PR, otherwise the comments above are going to be pretty mysterious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for author
Development

Successfully merging this pull request may close these issues.

5 participants