Skip to content

log scale and polar broken #24383

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
tacaswell opened this issue Nov 6, 2022 · 9 comments · Fixed by #24825
Closed

log scale and polar broken #24383

tacaswell opened this issue Nov 6, 2022 · 9 comments · Fixed by #24825
Milestone

Comments

@tacaswell
Copy link
Member

    [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)

@tacaswell tacaswell changed the title log-log and polar broken log scale and polar broken Nov 6, 2022
@tacaswell
Copy link
Member Author

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

@tacaswell tacaswell added this to the v3.7.0 milestone Nov 6, 2022
@chahak13
Copy link
Contributor

chahak13 commented Nov 9, 2022

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

@ksunden
Copy link
Member

ksunden commented Nov 10, 2022

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.

@QuLogic
Copy link
Member

QuLogic commented Nov 11, 2022

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.

@dstansby
Copy link
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()

Figure_1

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)

@dstansby
Copy link
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'}}

@Gerald-Meyers
Copy link

Gerald-Meyers commented 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.
image

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
                        )

image

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')
image

Here is another data set over a 1 degree domain.
image

And the same data with polar as before.
image

And with log scale.
image

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

@ZhiweiBai
Copy link

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants