Skip to content

Correct theta values when drawing a non-circular arc #8047

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 2 commits into from
Mar 10, 2017

Conversation

dstansby
Copy link
Member

@dstansby dstansby commented Feb 8, 2017

Fixes #8046. I'm not sure if this is the right place to do the correction, so a second opinion would be good. I've checked this works with a full range of angles.

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Feb 8, 2017
@@ -982,6 +982,23 @@ def test_canonical():
ax.plot([1, 2, 3])


@image_comparison(baseline_images=['arc_angles'])
Copy link
Member

Choose a reason for hiding this comment

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

add remove_text=True and style='default' to the decorator to get the new defaults + drop all of the text (which makes the test more stable).

@tacaswell
Copy link
Member

This will need an entry in whats new or api changes. The paranoid case here is that users have worked around this bug and we are now silently changing things under them so it needs to be documented.

@tacaswell
Copy link
Member

This looks like the correct place to do this to me. Ellipse is implemented by holding transforms to re-scale a circular path so pushing this down into Path.arc is not right and Ellipse is for full coverage so pushing this into the base-class is not right either.

@dstansby dstansby changed the title Correct theta values when drawing a non-circular ellipse Correct theta values when drawing a non-circular arc Feb 9, 2017
@dstansby
Copy link
Member Author

Does anyone know why the documentation build is failing with:

/Users/dstansby/matplotlib/doc/examples/units/ellipse_with_units.rst:8: WARNING: Exception occurred in plotting ellipse_with_units
 from /Users/dstansby/matplotlib/doc/mpl_examples/units/ellipse_with_units.py:
Traceback (most recent call last):
  File "/Users/dstansby/matplotlib/lib/matplotlib/sphinxext/plot_directive.py", line 525, in run_code
    six.exec_(code, ns)
  File "<string>", line 55, in <module>
  File "/Users/dstansby/matplotlib/lib/matplotlib/patches.py", line 1565, in __init__
    theta1 = theta_stretch(theta1, width / height)
TypeError: unsupported operand type(s) for /: 'TaggedValue' and 'TaggedValue'

@afvincent
Copy link
Contributor

As far as I understand, it seems like “width” and “height” are cm instances from this script and that the class used under the hood (TaggedValue) does not implement the division operation.

@dstansby
Copy link
Member Author

dstansby commented Feb 10, 2017

Would anyone object to me just getting rid of http://matplotlib.org/examples/units/ellipse_with_units.html ? It doesn't seem to be showing any unique capabilities of units, and the 'comparison' just looks the same to me.

(and does it matter if my new code breaks drawing an ellipse with units?)

@tacaswell
Copy link
Member

Yes and yes (although, it seems like the problem here is the exact unit implementation, not generally).

The unit support is an under-understood, but critical feature of mpl (JPL relies on it).

@dstansby
Copy link
Member Author

dstansby commented Feb 10, 2017

As far as I can tell:

  • The correct way to convert from units to a number is call self.convert_xunits(width)
  • However this is just returning width unchanged as units
  • This is because there is no axis when __init__ is called on Arc, so the units are returned unchanged

so all this means there's no way of converting units within the __init__ bit of Arc, so the conversion and angle correction needs to happen somewhere else.

@dstansby
Copy link
Member Author

That should fix it, I've moved the new calculation into the draw() method.

Copy link
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

LGTM mostly. Just a small tweak to the test.

theta2 = i * 360 / 9
theta1 = theta2 - 45
ax.add_patch(patches.Arc(centre, w, h, theta1=theta1, theta2=theta2))
# Straight line should intersect end of arc
Copy link
Member

Choose a reason for hiding this comment

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

Could you also add the start of the arc as well? Start -> origin -> end should work.

centre = (0.2, 0.5)

fig, axs = plt.subplots(3, 3)
for i, ax in enumerate(np.ravel(axs)):
Copy link
Member

Choose a reason for hiding this comment

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

enumerate(axs.flat)

for i, ax in enumerate(np.ravel(axs)):
theta2 = i * 360 / 9
theta1 = theta2 - 45
ax.add_patch(patches.Arc(centre, w, h, theta1=theta1, theta2=theta2))
Copy link
Member

Choose a reason for hiding this comment

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

Can you also add a full Ellipse patch with the same parameters but maybe half linewidth or alpha just to show that the arc is in a consistent place?

@dstansby
Copy link
Member Author

Thanks for the extra ideas for the test @QuLogic - once this has been reviewed I can squash everything down to a single commit.

@QuLogic
Copy link
Member

QuLogic commented Feb 28, 2017

Is there anything backend-specific here? Do we need the SVG/PDF files?

@dstansby
Copy link
Member Author

Oh yes, I forgot that those were optional. I don't think there's anything backend specific, shall I just have a .png image test?

@QuLogic
Copy link
Member

QuLogic commented Mar 2, 2017

Yes, I think we can drop the other ones and you can squash this.

Make arcs work with units

Add api change not for elliptical notes

Add background ellipse and extra line to test

Remove pdf and svg tests for arc angles
@dstansby
Copy link
Member Author

dstansby commented Mar 2, 2017

Great, that should be all nicely squashed up now.

Copy link
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

One more minor thing.

The `matplotlib.patches.Arc` patch is now correctly drawn between the given
angles.

Previously a circular are was drawn and then stretched into an ellipse,
Copy link
Member

Choose a reason for hiding this comment

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

are -> arc

Copy link
Member Author

Choose a reason for hiding this comment

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

woops...

@QuLogic QuLogic changed the title Correct theta values when drawing a non-circular arc [MRG+1] Correct theta values when drawing a non-circular arc Mar 9, 2017
@NelleV NelleV merged commit beeba66 into matplotlib:master Mar 10, 2017
@QuLogic QuLogic changed the title [MRG+1] Correct theta values when drawing a non-circular arc Correct theta values when drawing a non-circular arc Mar 11, 2017
@dstansby dstansby deleted the arc-theta branch April 2, 2017 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants