[Matplotlib-users] Arc and art3d.pathpatch_2d_to_3d

Thomas Caswell tcaswell at gmail.com
Wed Apr 22 13:16:07 EDT 2020


This is because `Arc` has a lot of logic in it's `draw` method to make sure
that the arcs draw correctly and efficiently even if you are zoomed in an a
small section, but uses the `Ellipse` patch as it's base (to manage the
major/minor axis, location, etc).   `Ellipse` works by setting some
internal state and then using the draw method from `Patch`.

What `art3d.pathpatch_2d_to_3d` does under the hood is change what
`__class__` the object thinks it is (!!) and tells your Arc it is now a
`Patch3D` and uses the state for the base Path state to draw its self,
which due to inheriting from Ellipse is the full ellipse.

Having said that, I don't have a good idea of how to fix this.  I think the
minimal solution is to adjust the path in `Arc` to clip it self to the
given range (so the up-convert to Path3D works) and to make sure that the
path re-sampling logic in the 2D draw still works on the pre-clipped path.

Tom

On Wed, Apr 22, 2020 at 4:38 AM Andreas Schneider <andreas_schn at web.de>
wrote:

> Hi,
>
> I'm trying to plot an arc in a 3d plot using patches.Arc and
> art3d.pathpatch_2d_to_3d. However, although the arc is correctly shown
> from theta1 to theta2 in a 2d plot, the 3d plot always shows the full
> circle. Here is a minimal example:
>
> from matplotlib import pyplot as plt
> from matplotlib import patches
> from mpl_toolkits.mplot3d import art3d
>
> fig = plt.figure()
> ax = fig.add_subplot(111, projection='3d')
> p = patches.Arc((0, 0), 0.5, 0.5, angle=0., theta1=0., theta2=45.)
> ax.add_patch(p)
> art3d.pathpatch_2d_to_3d(p, z=0, zdir="y")
> plt.show()
>
> I get a whole circle but want to have an arc only from 0 degrees to 45
> degrees. A corresponding 2d plot shows the arc correctly:
>
> fig = plt.figure()
> ax = fig.add_subplot(111)
> p = patches.Arc((0, 0), 0.5, 0.5, angle=0., theta1=0., theta2=45.)
> ax.add_patch(p)
> plt.show()
>
> What am I doing wrong with the conversion from 2d to 3d?
>
> I tried Python 3.7.3 with Matplotlib 3.0.2 and Python 2.7.16 with
> Matplotlib 2.2.3 (which are shipped with my Linux distribution).
>
> Thanks in advance for your help.
>
> Andreas
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
>


-- 
Thomas Caswell
tcaswell at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20200422/a6277acb/attachment.html>


More information about the Matplotlib-users mailing list