Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Display r and theta on hover for polar plots#26271

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
klorine28 wants to merge2 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromklorine28:fix-for-#4568

Conversation

klorine28
Copy link

@klorine28klorine28 commentedJul 6, 2023
edited
Loading

PR summary

PR checklist

@tacaswell
Copy link
Member

Thank you for your interest in contributing to Matplotilb, however this PR does not address the issue in#4568 .

The core issue is that for Cartesian plots there are functions you can set to control how the mouse over reports (seehttps://matplotlib.org/stable/gallery/misc/coords_report.html for the updated version of the docs, you will need to use an interactive backend (not matplotlib-inline in a notebook) to see it do anything) the x and y values. The issue reports that those functions are ignored on polar axes (see

defformat_coord(self,x,y):
"""Return a format string formatting the *x*, *y* coordinates."""
return"x={} y={}".format(
"???"ifxisNoneelseself.format_xdata(x),
"???"ifyisNoneelseself.format_ydata(y),
)
and
defformat_coord(self,theta,r):
# docstring inherited
screen_xy=self.transData.transform((theta,r))
screen_xys=screen_xy+np.stack(
np.meshgrid([-1,0,1], [-1,0,1])).reshape((2,-1)).T
ts,rs=self.transData.inverted().transform(screen_xys).T
delta_t=abs((ts-theta+np.pi)% (2*np.pi)-np.pi).max()
delta_t_halfturns=delta_t/np.pi
delta_t_degrees=delta_t_halfturns*180
delta_r=abs(rs-r).max()
iftheta<0:
theta+=2*np.pi
theta_halfturns=theta/np.pi
theta_degrees=theta_halfturns*180
# See ScalarFormatter.format_data_short. For r, use #g-formatting
# (as for linear axes), but for theta, use f-formatting as scientific
# notation doesn't make sense and the trailing dot is ugly.
defformat_sig(value,delta,opt,fmt):
# For "f", only count digits after decimal point.
prec= (max(0,-math.floor(math.log10(delta)))iffmt=="f"else
cbook._g_sig_digits(value,delta))
returnf"{value:-{opt}.{prec}{fmt}}"
return ('\N{GREEK SMALL LETTER THETA}={}\N{GREEK SMALL LETTER PI} '
'({}\N{DEGREE SIGN}), r={}').format(
format_sig(theta_halfturns,delta_t_halfturns,"","f"),
format_sig(theta_degrees,delta_t_degrees,"","f"),
format_sig(r,delta_r,"#","g"),
)
for updated perma-links from#4568 (comment) ).

The proposed fixes are to do one of the following:

  • addfmt_r andfmt_theta as analogs to the Cartesian versions
  • update theformat_coords method on polar axes to look at the fmt_xdata and fmt_ydata methods

See the discussion in the issue for pros and cons of each. The rough consensus seemed to be towards the second option.

@klorine28
Copy link
Author

I am unusre if my solution is of any help as it was not clear to me if the goal was to leave a possibe example or make a standarization to solve an underlying issue. i did however manage to get the example code working with the bits that were asked for.

@klorine28
Copy link
Author

so the issue is that interactive ploting features are ignored when the plot is polar? and the goal of the issue is to modify the code above to make it so that these interactive plotting functions are not ignored?

This modification uses the fmt_xdata and fmt_ydata methods by retrieving the corresponding formatters (fmt_theta and fmt_r) from the x-axis and y-axis, respectively, to format the theta and r values in the format_coord method.
@klorine28
Copy link
Author

is the change I made better?

@jklymak
Copy link
Member

@klorine28 ive not followed the suggestion here fully. However this is not in the form of either an example (galleries/examples) or what I think was being asked for, which is a modification to the polar axes that would display r and theta by default.

@klorine28
Copy link
Author

I apologise for this is my first interaction with open source that is not documentation. So what I am trying to do is modify the format coords so that r and theta are displayed by default? What I understood from the issue was that in cartesian plots, you can see the info of a point by interacting with it, but this is ignored in polar plots. As such, the solution would be to make it so that when you hover over a point in a polar plot, it displays theta and r. Is that correct?

@klorine28
Copy link
Author

any coment on my question? is the second commit what is wanted?

@melissawm
Copy link
Member

Hi@klorine28 - you may get more attention here if you rename your PR to something more descriptive, for example something like "Display r and theta on hover for polar plots" (please choose the wording that makes more sense to you). In addition, you can then add "Closes#4568" to the description of your PR to make sure it is linked to the original issue here in the GitHub web interface.

Beyond that, there are also a couple of Linting errors that you can fix while you wait for a review:https://github.com/matplotlib/matplotlib/actions/runs/5486484810/job/14858128627?pr=26271

Thanks!

@klorine28klorine28 changed the titlepossible solve for issue #4568Display r and theta on hover for polar plotsJul 22, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
Status: Waiting for author
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@klorine28@tacaswell@jklymak@melissawm

[8]ページ先頭

©2009-2025 Movatter.jp