Skip to content

Fixed PolarAxes not using fmt_xdata and added simple test (#4568) #28306

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

Merged
merged 3 commits into from
Jun 23, 2024

Conversation

decxxx
Copy link
Contributor

@decxxx decxxx commented May 26, 2024

PR summary

I've fixed PolarAxes to use fmt_xdata and fmt_ydata and added a few simple tests to test that functionality. (#4568)

PR checklist

@decxxx
Copy link
Contributor Author

decxxx commented May 27, 2024

Are those 2 checks from azure pipelines supposed to fail? I've noticed some other pull requests fail on exactly the same test.

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor styling comment.

Comment on lines 1456 to 1458
format_sig(r, delta_r, "#", "g")
if self.fmt_ydata is None
else self.format_ydata(r)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a bit confused by this portion as well when first glancing at this because it is duplicated below. I think this might be nice to bring outside the fmt_xdata if statement:

r_label = ... and then reference r_label here and the following code block.

Comment on lines 450 to 458
def test_custom_fmt_xdata():
ax = plt.subplot(projection="polar")
def millions(x):
return '$%1.1fM' % (x*1e-6)

ax.fmt_xdata = millions
assert ax.format_coord(2e5, 1) == "θ=$0.2M, r=1.000"
assert ax.format_coord(1, .1) == "θ=$0.0M, r=0.100"
assert ax.format_coord(1e6, 0.005) == "θ=$1.0M, r=0.005"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a test for the case with both fmt_xdata and fmt_ydata set?

It might be easier to do this all within a single test and add comments for the various cases.

Suggested change
def test_custom_fmt_xdata():
ax = plt.subplot(projection="polar")
def millions(x):
return '$%1.1fM' % (x*1e-6)
ax.fmt_xdata = millions
assert ax.format_coord(2e5, 1) == "θ=$0.2M, r=1.000"
assert ax.format_coord(1, .1) == "θ=$0.0M, r=0.100"
assert ax.format_coord(1e6, 0.005) == "θ=$1.0M, r=0.005"
def test_custom_fmt_xdata():
ax = plt.subplot(projection="polar")
def millions(x):
return '$%1.1fM' % (x*1e-6)
# Test only x formatter
ax.fmt_xdata = millions
ax.fmt_ydata = None
assert ax.format_coord(2e5, 1) == "θ=$0.2M, r=1.000"
assert ax.format_coord(1, .1) == "θ=$0.0M, r=0.100"
assert ax.format_coord(1e6, 0.005) == "θ=$1.0M, r=0.005"
# Test only y formatter
ax.fmt_xdata = None
ax.fmt_ydata = millions
...
# Test both x and y formatters
ax.fmt_xdata = millions
ax.fmt_ydata = millions
...

@greglucas greglucas merged commit aadb2c4 into matplotlib:main Jun 23, 2024
41 of 44 checks passed
@decxxx decxxx deleted the iss4568 branch June 24, 2024 10:13
@QuLogic QuLogic added this to the v3.10.0 milestone Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for author
Development

Successfully merging this pull request may close these issues.

Add fmt_r and fmt_theta methods to polar axes
4 participants