rougier / scientific-visualization-book

An open access book on scientific visualization using python and matplotlib
https://www.labri.fr/perso/nrougier/
Other
10.72k stars 993 forks source link

AttributeError: 'Arrow3D' object has no attribute 'do_3d_projection' #88

Closed EmmetZ closed 10 months ago

EmmetZ commented 10 months ago

I try to run code/scales-projections/projection-3d-frame.py and then there's an error: AttributeError: 'Arrow3D' object has no attribute 'do_3d_projection'

my env: python: 3.11, matplotlib: 3.8.0

then I found a possible solution here -> matplotlib issues#21688 when I change class Arrow3D to :

class Arrow3D(mpatches.FancyArrowPatch):
    def __init__(self, xs, ys, zs, *args, **kwargs):
        mpatches.FancyArrowPatch.__init__(self, (0, 0), (0, 0), *args, **kwargs)
        self._verts3d = xs, ys, zs

    def do_3d_projection(self, renderer=None):
        xs3d, ys3d, zs3d = self._verts3d
        xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, self.axes.M)
        self.set_positions((xs[0],ys[0]),(xs[1],ys[1]))
        return np.min(zs)

it works, so I think maybe projection-3d-frame.py need to be updated?

rougier commented 10 months ago

Thanks and yes. Can you make a PR?

EmmetZ commented 10 months ago

I have already made a PR(I hope I got it right), thanks for your wonderful book!

rougier commented 10 months ago

Merge, thanks for your contribution.