如何在标准图中直接使用matplotlib中的Axes3D以避免flake8错误 [英] How to directly use Axes3D from matplotlib in standard plot to avoid flake8 error

查看:955
本文介绍了如何在标准图中直接使用matplotlib中的Axes3D以避免flake8错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用像这样的典型3D图时:

When using the typical 3D plot like so:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.gca(projection='3d')

flake8报告预期的错误:

./tools.py:62:9: F401 'mpl_toolkits.mplot3d.Axes3D' imported but unused

我知道可以使用# NOQA注释来避免这种情况.但是,有没有其他方法可以在图中表示投影,以便使用Axes3D对象?

I know it can be avoided using the # NOQA comment. But is there a different way to formulate the projection in the figure so that the Axes3D object is used?

推荐答案

如果这仅是至少实际使用一次导入,则可以

If this is only about actually using the import at least once, you can do

ax = fig.gca(projection=Axes3D.name)

as "3d"Axes3D类的名称,通过该类将其注册到投影列表中.

as "3d" is the name of the Axes3D class by which it is registered to the projection list.

这篇关于如何在标准图中直接使用matplotlib中的Axes3D以避免flake8错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆