FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[Bug]: set_rticks makes polar autoscale move the origin away from zero · Issue #29528 · matplotlib/matplotlib · GitHub

Repository navigation

[Bug]: set_rticks makes polar autoscale move the origin away from zero #29528

Closed

Description

Bug summary

On polar axes, autoscaling (which only applies on the radial direction) normally avoids moving the origin away from r=0 (unless there's negative radius data). However, this behavior is lost if set_rticks has been called first.

(split out of #29516)

Code for reproduction

import matplotlib.pyplot as plt

ax = plt.figure().add_subplot(projection="polar")
ax.plot([0, 1], [2, 3])  # theta, r
print(ax.get_ylim())  # -> rlim = (0, 3.05), OK: lower r=0 bound forced

ax = plt.figure().add_subplot(projection="polar")
ax.set_rticks([1, 2, 3, 4])
print(ax.get_ylim())  # -> rlim = (0, 4), OK
ax.plot([0, 1], [2, 3])  # theta, r
print(ax.get_ylim())  # -> rlim = (1.95, 3.05), oops: lower r=0 bound lost

Actual outcome

See comments in code.

Expected outcome

The last autoscaling should also set rlims to (0, 3.05).

Additional information

No response

Operating system

any

Matplotlib Version

3.11.0.dev342+g3b54c6abab

Matplotlib Backend

agg

Python version

3.13

Jupyter version

no

Installation

git checkout

Activity

  1. added 3 commits that reference this issue on Mar 20, 2025
    1d1af91
    9c46f5a
    88a4424
  2. rcomer commented on Mar 24, 2025

    Member

    I think the problem is that set_rticks replaces the RadialLocator with the FixedLocator. The view_limits method on the RadialLocator is what usually keeps the origin at or below zero.

    def view_limits(self, vmin, vmax):
    vmin, vmax = self.base.view_limits(vmin, vmax)
    if self._zero_in_bounds() and vmax > vmin:
    # this allows inverted r/y-lims
    vmin = min(0, vmin)
    return mtransforms.nonsingular(vmin, vmax)

    Do we need to implement a RadialFixedLocator?

  3. timhoffm commented on Mar 24, 2025

    Member

    Do we need to implement a RadialFixedLocator?

    The RadialLocator is a wrapper around a base locator. Would it work to set RadialLocator.base to the FixedLocator?

  4. rcomer commented on Mar 25, 2025

    Member

    Oh, maybe we just need to call self.yaxis._wrap_locator_formatter within set_rticks

    def _wrap_locator_formatter(self):
    self.set_major_locator(RadialLocator(self.get_major_locator(),
    self.axes))
    self.isDefault_majloc = True

    @bruswaine do you want to give that a try?

  5. bruswaine commented on Mar 25, 2025

    Contributor

    @rcomer yes. I have already altered my solution to one that uses the RadialLocator, very similar to what you proposed and it seems to work. Should i open a new PR or just commit to the branch in my fork? Sorry im not sure how it works. Thanks for the help

  6. rcomer commented on Mar 25, 2025

    Member

    @bruswaine great - it seems you are ahead of me! It's fine to commit to your existing branch.

  7. added 2 commits that reference this issue on Mar 25, 2025
    273dff3
    c142cfa
  8. added a commit that references this issue on Mar 29, 2025
    2933275
  9. added this to the v3.11.0 milestone on Mar 29, 2025
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL