-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Polar errcaps #23592
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
Polar errcaps #23592
Conversation
e22defa
to
d2fa4cd
Compare
I guess I'm confused. Is this a theta error? If so, it should be drawn as a curve and kept at the same radius as the data point? |
That is probably the ideal solution, yes. Similar to the lines not directly connecting the points, but uses some sort of curve. However, considering the current output this PR is clearly a step in the right direction, actually making it possible to use error caps. On the other hand, it shouldn't be impossible to use an Arc instead and orient the caps pointing to the center. But if noone is implementing that, I'd clearly go for this solution in the meantime. (One can also think about if the caps for errorbars in the other direction should be rounded or not?) |
Yes, if we want to be exact, theta errors should be curved. However, personally, I would not be that pedantic. Errors should be reasonably small (or the visualization does not tell much anyway). And fore small errors, a straight theta-line is a reasonable approximation of the curve. So if somebody wants to implement curved theta bars, great. But I would live with straight that-bars, if that's all we can do with reasonable effort now. That said, I can also see an argument for not supporting theta bars at all if they are not curved. |
If you can see the tilt for uncentred bars, I assume you can also see that they are not curved? |
The original (rejected) solution in PR #21006 looked like this:
On the other hand, under different settings I believe that curved theta error is must have, consider following plot:
|
Closes #441. |
This needs to go in the original description, a commit message, or you can link with the Description section in the right sidebar. Putting it here though, doesn't do anything. Unfortunately, #441 doesn't show up here to be linked, but if you go there, this PR shows up to be linked, which I've now done. |
715e544
to
d712e61
Compare
I have fixed the testing figure. Additionally I have fixed the issue with radial offset for large error bars, see below: import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(figsize=(10,10))
ax = plt.subplot(111, projection='polar')
theta = np.arange(0, 2*np.pi, np.pi / 4)
r = theta / np.pi / 2 + 0.5
ax.errorbar(theta, r, xerr=0.25, capsize=7, fmt="o") Additionally I have done some experiments with curved error bars: You can see proof of principle with code changes here |
And just to make decision even harder, here I show some bar graphs with error bars: import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(figsize=(10,10))
ax = plt.subplot(111, projection='polar')
theta = np.arange(0, 2*np.pi, np.pi / 4)
r = theta / np.pi / 2 + 0.5
ax.errorbar(theta, r, xerr=0.25, yerr=0.1, capsize=7, fmt="o")
ax.bar(theta, r, width=0.4, bottom=0.0, alpha=0.5) |
Nice! I guess the best thing now is to discuss it at the dev-call on Thursday? Feel free to join if you want! (Personally, I think that the curved error bars is the way to go.) |
I agree: The curved error bars is what we want. |
This was discussed on the weekly call. The consensus was curved error bars and wait for it all to be ready for 3.7 rather than squeezing this in for 3.6 with straight lines. We also discussed the interpolate step (private) feature of |
70c6382
to
b9813ec
Compare
cf7ca12
to
fec9b60
Compare
fec9b60
to
c77fc36
Compare
c77fc36
to
91a0877
Compare
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.
This looks good to me. However, can it get an example for the gallery, and the what's-new link the example?
8e82830
to
b40e2f7
Compare
I have added an gallery example (just a simple one), but I am not sure that the link in |
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.
Small nit that you take or leave...
import matplotlib.pyplot as plt | ||
|
||
fig = plt.figure(figsize=(10, 10)) | ||
ax = plt.subplot(111, projection='polar') |
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.
This would be more idiomatic, but not a big deal:
ax = plt.subplot(111, projection='polar') | |
ax = fig.add_subplot(projection='polar') |
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 will fix it, I am taking some time to think of a more elaborate gallery example :-)
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.
Ok, I could not think of something better. I have just added overlapping examples, including your suggestions.
Caps and error lines are now drawn with respect to polar coordinates, | ||
when plotting errorbars on polar plots. | ||
|
||
.. figure:: /gallery/pie_and_polar_charts/images/sphx_glr_polar_error_caps_001.png |
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.
If this works, great! (not sure it will, but my ignorance of sphinx is relatively vast)
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 just mimicked it from this what's new message, but it does not seem to work properly in the built documentation, so I am not sure it is worth the try.
- uses _interpolation_steps - prefers transform MarkerStyle in init over _transform property - adjusted what's new - added more tests for overlapping, asymmetric and long errorbars - combine all tests to a single figure - remove overlappnig since it does not work same on all platforms - rework test figure, add overlapping, might work by avoiding grid - update what's new with image and link to example
a7fc4b6
to
b7c27d5
Compare
PR Summary
Trying to reopen #21006, including fix for theta error bars.
I had to squash original contribution from @dstansby to pass through
PR cleanliness
, if there is any other way to reopen the original PR I would gladly do it (however, I couldn't figure it out).The changes are minor, just changing the order of resolving "polar" criterion.
The fix is based on fact that to achieve markers perpendicular to the error bar, we need to find the error bar "midpoint theta", this is done by averaging lower and upper theta limit.
I have checked that it works for uneven error bars, see images comments.
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).