Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: set_theta_offset removes grid outline #26972

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

Open
am-thyst opened this issue Oct 2, 2023 · 9 comments · May be fixed by #26991
Open

[Bug]: set_theta_offset removes grid outline #26972

am-thyst opened this issue Oct 2, 2023 · 9 comments · May be fixed by #26991

Comments

@am-thyst
Copy link

am-thyst commented Oct 2, 2023

Bug summary

When producing a polar plot, set_theta_offset removes the outer gridlines.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
fig, (ax1,ax2) = plt.subplots(1,2,subplot_kw=dict(projection='polar'))

azis = np.radians(np.linspace(0,360,72)); r = np.linspace(0, 250, 250)
dats = np.random.rand(250,72)
X,Y=np.meshgrid(azis,r)

for ax in [ax1,ax2]:
    ax.contourf(X,Y,dats,cmap="RdYlBu")

ax2.set_theta_offset(1.570796327)
plt.subplots_adjust(wspace=0.5)

Actual outcome

First axis has no "set_theta_offset", which means the plot starts at 90. Second axis has "set_theta_offset", which rotates the plot to start at 0, but it removes the black outline.

image

Expected outcome

Expect ax2 above to have a black circular outline as in ax1.

Additional information

No response

Operating system

Windows

Matplotlib Version

3.7.1

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.11.3

Jupyter version

6.5.4

Installation

conda

@stevezhang1999
Copy link
Contributor

Thanks for reporting this. However I cannot run the script and it looks like you forgot to include the definition of "azis" and "r" in the script. Would you add that so we can get the exactly same result as you?

@am-thyst
Copy link
Author

am-thyst commented Oct 2, 2023

@stevezhang1999 thanks for flagging that, have updated now

@stevezhang1999
Copy link
Contributor

@stevezhang1999 thanks for flagging that, have updated now

Thanks, now I can reproduce this with mpl = 3.7.2

@stevezhang1999
Copy link
Contributor

A simpler example to reproduce issue

import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1,subplot_kw=dict(projection='polar'))

ax.set_theta_offset(1.570796327)
plt.subplots_adjust(wspace=0.5)

image

@ksunden
Copy link
Member

ksunden commented Oct 2, 2023

It looks like you are mostly referring to the "spine" (the bold outline) xref #16066 for that

But also seems to have problems with gridlines still... and I'm reminded of an idea from #24996 of possibly using axhline for gridlines, which may help?

@stevezhang1999
Copy link
Contributor

I think this results from a calculation flaw within path.arc so this is not directly related to #16066. Will open a PR for more details and the fix tomorrow (hopefully)

@am-thyst
Copy link
Author

am-thyst commented Oct 3, 2023

Similar to the axhline suggestion, I can create a quick workaround for the "spine" using a plot command like this:

ax.plot(np.linspace(0, 2*np.pi, 50), np.ones(50)*250, color='black', linestyle='solid',linewidth=2)

This is much more relevant for my uses anyway, but obviously doesn't solve the bug within matplotlib.

@QuLogic
Copy link
Member

QuLogic commented Oct 3, 2023

@stevezhang1999 do you think this is something more like #13717?

@stevezhang1999
Copy link
Contributor

stevezhang1999 commented Oct 3, 2023

@stevezhang1999 do you think this is something more like #13717?

Update: I think the results in #13717 looks good. Path.arc doesn't document what will happen if theta1 is greater than theta2. As long as (theta1 - theta2) is not close enough to multiple of 360, it's unlikely that we will suffer from the floating point comparison error from roundoff.

I suspect that they are related and will look at it later tonight. To fix this issue, I believe we need to replace the floating point comparison inside with np.isclose() - but it will break many tests and I’m still looking at them.

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.

5 participants