-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Conversation
Are those 2 checks from azure pipelines supposed to fail? I've noticed some other pull requests fail on exactly the same test. |
There was a problem hiding this 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.
lib/matplotlib/projections/polar.py
Outdated
format_sig(r, delta_r, "#", "g") | ||
if self.fmt_ydata is None | ||
else self.format_ydata(r) |
There was a problem hiding this comment.
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.
lib/matplotlib/tests/test_polar.py
Outdated
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" |
There was a problem hiding this comment.
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.
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 | |
... |
PR summary
I've fixed
PolarAxes
to usefmt_xdata
andfmt_ydata
and added a few simple tests to test that functionality. (#4568)PR checklist
fmt_r
andfmt_theta
methods to polar axes #4568" is in the body of the PR description to link the related issue