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

log scale and polar broken · Issue #24383 · matplotlib/matplotlib · GitHub

Repository navigation

log scale and polar broken #24383

Closed

Description

    [09192022_NaCl_0-2mmS_3mmD_0D_0-0.01inc_0.5dpm(high res).txt](https://github.com/matplotlib/matplotlib/files/9944614/09192022_NaCl_0-2mmS_3mmD_0D_0-0.01inc_0.5dpm.high.res.txt)

Example of working code is:

     fig, ax = subplots( 1, 1,
                        figsize=(8, 8),
                        subplot_kw={ 'projection':'polar' },
                        )
    xvals, yvals = data
    # yscale('log')
    # ax.set_theta_zero_location( 'N' )
    # ax.set_theta_direction( -1 )
    # ax.set_rscale( 'log' )
    # ax.set_rlim((0,max(yvals)))
    
    polar( xvals, yvals,
             label=params.get( 'datalabel' ),
             )
    
    savefig( f"{params.get( 'fname' )}_polar" )
    close( fig=fig )

Plot functions correctly(ish) but when set to a log-plot the plot malfunctions: the error ""posx and posy should be finite values"" and the entire plot is a blank circle. The 'r' labels are still not correct normally.

Originally posted by @Gerald-Meyers in #11202 (comment)

Activity

  1. changed the title [-]log-log and polar broken[/-] [+]log scale and polar broken[/+] on Nov 6, 2022
  2. tacaswell commented on Nov 6, 2022

    MemberAuthor

    @Gerald-Meyers could you possibly trim that data down to the minimal needed to reproduce (or is this not data dependent)?

  3. added this to the v3.7.0 milestone on Nov 6, 2022
  4. chahak13 commented on Nov 9, 2022

    Contributor

    This bug doesn't seem data dependent. Here's a small reproduction

    import matplotlib.pyplot as plt
    
    fig, ax = plt.subplots(1, 1, figsize=(8, 8),
                            subplot_kw={'projection': 'polar'})
    xvals, yvals = [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]
    ax.plot(xvals, yvals)
    ax.set_yscale('log')
    plt.show()

    Which gives this error

    /home/chahak/Documents/matplotlib/issue_24383.py:14: UserWarning: Attempt to set non-positive ylim on a log-scaled axis will be ignored.
      plt.show()
    posx and posy should be finite values
    posx and posy should be finite values
    
  5. ksunden commented on Nov 10, 2022

    Member

    Appears to be related to RadialLocator.view_limits

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

    In particular I'm suspicious that the vmin capping at 0 may not be desirable with log scale, but haven't fully worked out the details.

  6. QuLogic commented on Nov 11, 2022

    Member

    The 0 cap was added to preserve old behaviour from when it didn't support negative radii. However, I don't think log scales were supported then either.

  7. dstansby commented on Nov 12, 2022

    Member

    I've idependently stumbled upon this investigating something else. An even smaller example:

    import matplotlib.pyplot as plt
    
    fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
    ax.set_yscale('log')
    
    plt.show()

    posx and posy should be finite values
    posx and posy should be finite values
    posx and posy should be finite values
    posx and posy should be finite values
    /Users/dstansby/github/matplotlib/lib/matplotlib/scale.py:253: RuntimeWarning: overflow encountered in power
      return np.power(self.base, a)
  8. dstansby commented on Nov 12, 2022

    Member

    At least one issue is the polar limits are not being set to finite values (ie. on a log scale, vmin > 0):

    import matplotlib.pyplot as plt
    
    for kw in [{}, dict(subplot_kw={'projection': 'polar'})]:
        fig, ax = plt.subplots(**kw)
        ax.set_yscale('log')
        print(ax.get_ylim(), kw)

    (0.8912509381337456, 11.220184543019636) {}
    (0.0, 1.0) {'subplot_kw': {'projection': 'polar'}}

  9. Gerald-Meyers commented on Nov 12, 2022

    @Gerald-Meyers could you possibly trim that data down to the minimal needed to reproduce (or is this not data dependent)?

    I can assure you I tested this on 6 different data sets. The data is not the problem. It it matters, you are more than welcome to slice the data when you np.genfromtxt. The polar plot did function as expected without radial log-scale. However, the circular grid lines for the r values ranged from 0 to 1, not from 0 to 1e7.

    For example, here is normal plot of one of my data sets without any log-scale over the domain [20,80]=Δ60 degrees.

    Here is the same data set, but with the extra line of code

    fig, ax = subplots( 1, 1,
                            figsize=(8, 8),
                            subplot_kw={'projection':'polar'} # <- extra line
                            )
    

    It is worth noting that there are no non-positive(=negative,zero) values in this data set. And the same polar plot when I enable the radial log-scale with
    plt.yscale('log')

    Here is another data set over a 1 degree domain.

    And the same data with polar as before.

    And with log scale.

    Clearly there are a few more issues than just 'log-scale' broken.

  10. ZhiweiBai commented on Apr 15, 2024

    I found a solution to this problem, just upgrade the package pip install --upgrade matplotlib

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