How to use Axes3D from matplotlib directly in standard plot to avoid flake8 error
When using a typical 3D plot:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
flake8
reports the expected error:
./tools.py:62:9: F401 'mpl_toolkits.mplot3d.Axes3D' imported but unused
I know it can be avoided by using a comment # NOQA
. But is there another way to formulate the projection in the picture so that the Axes3D object is used?
+3
dsalaj
source
to share
1 answer
If it is about actually using the import at least once, you can do
ax = fig.gca(projection=Axes3D.name)
as "3d"
is the name of the class Axes3D
by which it is registered in the projection list.
+10
ImportanceOfBeingErnest
source
to share