Skip to content

add label alignment to tick_params #20644

Open

Description

@story645

tick_params supports a subset of labeling parameters:

  • labelcolor
  • labelsize
  • label{bottom, top, left, right}
  • labelrotation

Motivated by wanting to swap out plt.setp and use tick_params, and finding the tick_params list kind of arbitrary, I think if labels can be modified via tick_params than a larger set of label parameters should be supported. This would mean adding:

Activity

  1. changed the title [-]add label alignement to tick_params[/-] [+]add label alignment to tick_params[/+] on Jul 17, 2021
  2. timhoffm commented on Aug 19, 2021

    @timhoffm
    Member

    Not sure if that's too much magic, but IMHO tick labels should always "point" to their tick. That would require different alignment depending on the rotation angle.

    It could be an option not to expose explicit alignment but automatically choose it depending on the angle. (You could still use setp() if you need full control over all tick properties).

  3. story645 commented on Aug 19, 2021

    @story645
    MemberAuthor

    I totally agree w/ you on an automagical angle alignment as that's probably a common use case.

  4. story645 commented on Jul 14, 2022

    @story645
    MemberAuthor

    Labeling good first issue because it seems to have support from at least two devs and is somewhat independent, but medium difficulty because it's kind of involved:

    1. adding more dispatch in
      def tick_params(self, axis='both', **kwargs):
    2. adding more kwarg support to
      def set_tick_params(self, which='major', reset=False, **kw):
    3. modify some methods on the tick class to support the new keywords
      class Tick(martist.Artist):

    (ETA: probably in 3,2,1 order) + tests for all the new kwargs (which I think means image tests?)

  5. added
    Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
    🌱 Good first issueOpen a pull request against these issues if there are no active ones!
    on Jul 14, 2022
  6. QuLogic commented on Jul 15, 2022

    @QuLogic
    Member

    (which I think means image tests?)

    I think it can check [label.get_[vh]a() for label in get_ticklabels()]? (or via some similar new getter API if it gets added.)

  7. joooeey commented on Jun 7, 2023

    @joooeey

    (You could still use setp() if you need full control over all tick properties).

    I've heard the setp excuse a lot all over this issue tracker and Stackoverflow in many contexts but it has a major flaw: For those of us working with interactive plots, we have to somehow make sure that setp is called after re-drawing when the ticks change.

    Can anyone enlighten me what the reason is that we don't provide a mechanism to pass all keyword arguments to the ticks and labels through the various .tick_params and .set_tick_params methods? Is this just not implemented yet or are there major obstacles?

  8. timhoffm commented on Jun 7, 2023

    @timhoffm
    Member

    This ist mostly "just not implemented". However I except that there can be some corner cases (e.g. the alignment discussion above), where we might want to deviate from simply passing through.

  9. timhoffm commented on Dec 9, 2024

    @timhoffm
    Member

    While not a replacement, the new rotation modes in #28968 remove the need for explicit alignment control for one of the current most common use cases: fix tick alignment after rotation.

  10. evelyn-lo commented on Apr 20, 2025

    @evelyn-lo

    Hi @timhoffm ! I'm Evelyn, and am interested in helping resolve this issue. Can me and my team work on this?

  11. timhoffm commented on Apr 21, 2025

    @timhoffm
    Member

    Hi @evelyn-lo thanks for your interest. I'm still unclear whether we should support the alignment. If so, it would have the effect as described here, which should explicitly be mentioned as it may not be the obvious behavior.

  12. added a commit that references this issue on May 4, 2025
  13. rcomer commented on Jun 2, 2025

    @rcomer
    Member

    The use case that springs to mind for me is the third example here, where we add a bunch of spaces to move the month labels to the right. Ideally we could set the horizontal_alignment to left instead

    https://matplotlib.org/stable/gallery/ticks/multilevel_ticks.html

    # note the extra spaces in the label to align the month label inside the month.
    # Note that this could have been done by changing ``bymonthday`` above as well:
    sec.xaxis.set_major_formatter(mdates.DateFormatter('  %b'))

    Admittedly this is a pretty specialised case.

  14. rcomer commented on Jun 19, 2025

    @rcomer
    Member

    We should remove the GFI label while we decide if we still want this.

  15. removed
    🌱 Good first issueOpen a pull request against these issues if there are no active ones!
    on Jun 19, 2025
  16. timhoffm commented on Aug 24, 2025

    @timhoffm
    Member

    The use case that springs to mind for me is the third example here, where we add a bunch of spaces to move the month labels to the right. Ideally we could set the horizontal_alignment to left instead

    I don't think this would even help here. The day tick labels are center-aligned. The spacing emulates left-alignment to te day tick labels. but a possible tick_params(horizontalalignment='left') would left-align to the tick not to the day tick label. Alternatively left aligning bot the day label and the month label wrt. to the tick is possibly also not desirable here.


    repeating #30009 (comment):

    given, #20644 (comment) and #20644 (comment) i tend towards not implementing label alignment. Are there compelling use cases that still need to set this? If so, is the per-text alignment logic the right one or would one rather need a global function similar to align_titels \ align_labels?

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