-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
[Bug]: AttributeError: 'Arrow3D' object has no attribute 'do_3d_projection' #21688
Comments
Do you know what version of Matplotlib this last worked with? Thanks! |
It starts to fail with |
I think this is another bit of fallout from merging the internal representation of axes children from any lists to 1 list. Previously, the The fix here is to correct import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.patches import FancyArrowPatch
from mpl_toolkits.mplot3d import proj3d
class Arrow3D(FancyArrowPatch):
def __init__(self, xs, ys, zs, *args, **kwargs):
super().__init__((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)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
arrow_prop_dict = dict(mutation_scale=20, arrowstyle='-|>', color='k', shrinkA=0, shrinkB=0)
a = Arrow3D([0, 10], [0, 0], [0, 0], **arrow_prop_dict)
ax.add_artist(a)
plt.show() |
This works fine, thanks @tacaswell ! |
That should be |
Fixes #475 Thanks @ndevenish for the report and initial starting point at matplotlib/matplotlib#21688. That implementation didn't give us the nice Z zoom that we want, so after some digging, set_zlim gets us there. The call to nonsingular is what set_zlim does if zmin == zmax, as is the case for a flat detector. It seems to expand out the Z a bit. Calling it directly avoids a UserWarning. Also fix orthographic=True (not sure when this broke)
Since the initial release of the book there have been updates of Matplotlib. So the code for Listing 3-1 isn't working anymore. Changes are made with respect to matplotlib/matplotlib#21688 (comment)
Exact Code .. here %pylab inline from matplotlib import pyplot as plt class Arrow3D(FancyArrowPatch):
fig = plt.figure(figsize=(7,7)) ax.plot(df['feature1'], df['feature2'], df['feature3'], 'o', markersize=8, color='blue', alpha=0.2) plt.title('Eigenvectors') plt.show() |
@Siddhartha082 I do not understand what you are trying to say. |
Thanks you @tacaswell ! |
NB,NB,NB |
Can this class just be added to the library? |
Bug summary
New (appears in
matplotlib=3.5
) anAttributeError
is thrown stating'Arrow3D' object has no attribute 'do_3d_projection'
.The error appears when running, e.g., the nice example https://stackoverflow.com/a/29188796 by @tacaswell . Below I extracted a MWE from the stackoverflow code.
Code for reproduction
Actual outcome
[@tacaswell edited to add markup]
Expected outcome
Should draw the fancy arrow.
Additional information
This worked before matplotlib 3.5; error appears in different Python versions and different backends.
Operating system
Linux
Matplotlib Version
3.5.0
Matplotlib Backend
module://ipykernel.pylab.backend_inline
Python version
No response
Jupyter version
No response
Installation
conda
The text was updated successfully, but these errors were encountered: