Skip to content

Polar plot label rotation ignored #10882

Open

Description

Bug report

Bug summary

In matplotlib 2.0.2 you could rotate the axes labels on a polar plot, just as with any other plot

for i, label in enumerate(ax.get_xticklabels()):
    label.set_rotation(i*90)

This is not possible anymore with matplotlib 2.2.2

Code for reproduction

import matplotlib
import numpy as np
import matplotlib.pyplot as plt


fig=plt.figure(figsize=(4,3))
ax = plt.subplot(111, polar=True)
ax.set_xlabel("Matplotlib "+matplotlib.__version__)
ticks = np.arange(3)*np.pi/2.
labels = ["".join([a]*5) for a in list("ABC")]

plt.xticks(ticks, labels, size=16)
for i, label in enumerate(ax.get_xticklabels()):
    label.set_rotation(i*90)

plt.tight_layout()
plt.show()

Actual outcome with matplotlib 2.2.2

The rotation of the labels is simply ignored.

image

Expected outcome (as with 2.0.2)

We would expect to see the labels rotated as in this plot, produced by the same code run on matplotlib 2.0.2.

image

Activity

  1. added this to the milestone on Mar 27, 2018
  2. ImportanceOfBeingErnest commented on Mar 29, 2018

    @ImportanceOfBeingErnest
    MemberAuthor

    I think this is also related to #10105 where alignment is ignored.
    At the end it might all be related to #9068 or #9881?

  3. QuLogic commented on Mar 30, 2018

    @QuLogic
    Member

    What's the end goal exactly? There are some workarounds, depending on what you want to do.

  4. ImportanceOfBeingErnest commented on Mar 30, 2018

    @ImportanceOfBeingErnest
    MemberAuthor

    The goal would be to set any text properties like rotation, alignment, rotation_mode on the ticklabels just as it is possible with cartesian axes and as it was possible with polar axes.

  5. Aclant commented on Mar 31, 2018

    @Aclant

    Currently the problem is that the text on the graph is ticklabels which is not defined as a text whose rotation can be modified. Normally the text whose rotation can be modified is defined in text.py but when creating the ticks the label is not created with this type. We can use the set_rotation because when the label is creat by the user the label is bind on the text.py type with set_ticklabels in axis.py. I think this ask creators to refactor the code design. I am sure about this because if in text.py in init you add a default value, when you creat ticks.label the rotation value is not the default one.
    text.py :
    def init(self,
    x=0, y=0, text='',
    color=None, # defaults to rc params
    verticalalignment='baseline',
    horizontalalignment='left',
    multialignment=None,
    fontproperties=None, # defaults to FontProperties()
    rotation=92,
    linespacing=None,
    rotation_mode=None,
    usetex=None, # defaults to rcParams['text.usetex']
    wrap=False,
    **kwargs
    ):
    """
    Create a :class:~matplotlib.text.Text instance at x, y
    with string text.

        Valid kwargs are
        %(Text)s
        """
    
        Artist.__init__(self)
        self._x, self._y = x, y
    
        if color is None:
            color = rcParams['text.color']
        if fontproperties is None:
            fontproperties = FontProperties()
        elif isinstance(fontproperties, six.string_types):
            fontproperties = FontProperties(fontproperties)
    
        self.set_text(text)
        self.set_color(color)
        self.set_usetex(usetex)
        self.set_wrap(wrap)
        self._verticalalignment = verticalalignment
        self._horizontalalignment = horizontalalignment
        self._multialignment = multialignment
        self.set_rotation(rotation)
        self._fontproperties = fontproperties
        self._bbox_patch = None  # a FancyBboxPatch instance
        self._renderer = None
        if linespacing is None:
            linespacing = 1.2   # Maybe use rcParam later.
        self._linespacing = linespacing
        self.set_rotation_mode(rotation_mode)
        self.update(kwargs)
    
  6. ImportanceOfBeingErnest commented on Apr 1, 2018

    @ImportanceOfBeingErnest
    MemberAuthor

    I think this ask creators to refactor the code design.

    @Aclant Yes this is somehow the definition of a GitHub issue.

    You may print type(label) to see that the labels are indeed matplotlib.text.Text instances. Their properties can be changed as usual with .set_<property>. The problem here is that those settings are reverted once they are drawn according to a general property set within the axis class.
    This has been introduced deliberately to easily produce rotated labels by default, however it now prevents modifying them individually.
    I would guess that people are well aware of the cause of this issue; the only question would be on how to allow for individual settings without throwing all the nice automatic labeling in the bin.

  7. ImportanceOfBeingErnest commented on May 3, 2018

    @ImportanceOfBeingErnest
    MemberAuthor

    @tacaswell A final example: As I see it this issue is a regression to 2.0.2. However there seem to have been a reason to make the changes that led to this, implicitely removing the option to rotate labels and without notifying about workarounds. So while technically I would be able to fix this, I cannot do it because it's unclear how those changes are meant to be preserved in the intended usecase while still allowing for the rotated ticklabels. In case there were clear instructions here I could surely fix this and it could be backported as a regression fix.

  8. ImportanceOfBeingErnest commented on Jun 5, 2018

    @ImportanceOfBeingErnest
    MemberAuthor

    Related to this: It is equally not possible to set the font-weight to the ticklabels.

    Suppose we want to make the radial ticklabels of a polar plot bold (like in this SO question). In matplotlib 2.0 you could do

    plt.setp(ax.get_yticklabels(), fontweight="bold")
    

    This doesn't work any more due to the changes made in #9068 or #9881.

    Alternatively I though one could use

    ax.set_rgrids(..., fontweight="bold")
    

    which works for circular polar plots, but

    1. requires to know the tick positions in advance and replaces the automatic locator by a FixedLocator
    2. does not work with wedged polar plots

    So there is currently no way to make the rticklabels of a polar plot bold.

  9. modified the milestones: v3.0, v3.1 on Aug 11, 2018
  10. modified the milestones: v3.1.0, v3.2.0 on Mar 18, 2019
  11. 1 remaining item

  12. github-actions commented on May 2, 2023

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  13. added
    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.
    on Jun 1, 2023
  14. gonzabk commented on Jul 27, 2023

    @gonzabk

    Having the same problem on july 2023 :)

  15. melissawm commented on Aug 8, 2023

    @melissawm
    Member

    I will reopen until we can discuss what's the best strategy here - feel free to close if it's not actionable.

  16. removed
    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.
    on Aug 9, 2023
  17. added
    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.
    on Sep 11, 2023
  18. added
    keepItems to be ignored by the “Stale” Github Action
    and removed
    status: inactiveMarked by the “Stale” Github Action
    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.
    on Sep 11, 2023
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions