axes3d.plot_wireframe(X,Y,Z)错误 [英] axes3d.plot_wireframe(X,Y,Z) Error

查看:51
本文介绍了axes3d.plot_wireframe(X,Y,Z)错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 youtube 上的教程学习 Python,但在使用 3D 图形时遇到了一些困难.长话短说,我不断得到(如果

I'm trying to learn Python through a tutorial on youtube and I'm having some difficulies working with 3D graphs. Long stories short, I continuously get (if

Z.ndim != 2:
AttributeError: 'list' object has no attribute 'ndim')

尝试启动这个简单程序时出错:

error while trying to launch this simple program:

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

fig = plt.figure()

chart = fig.add_subplot(1,1,1,projection = '3d')

X,Y,Z = [1,2,3,4,5,6,7,8],[2,5,3,8,9,5,6,1],[3,6,2,7,5,4,5,6]

chart.plot_wireframe(X,Y,Z)

plt.show()

我知道它与 Axes3.plot_wireframe()方法有关,但是谁能向我解释发生了什么.

I know that it is related to the Axes3.plot_wireframe() method but Could anyone explain to me what's happening.

推荐答案

我通过做两件事解决了这个问题.

I walked around this problem by doing two things.

  1. 将 numpy 导入为 np
  2. 使z轴成为多维数组

#My 3d graph

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
import numpy as np

figure = plt.figure()
axis = figure.add_subplot(111, projection = '3d')

x = [1,2,3,4,5,6,7,8,9,10]
y = [5,6,7,8,2,5,6,3,7,2]
z = np.array([[1,2,6,3,2,7,3,3,7,2],[1,2,6,3,2,7,3,3,7,2]])

axis.plot_wireframe(x, y, z)

axis.set_xlabel('x-axis')
axis.set_ylabel('y-axis')
axis.set_zlabel('z-axis')

plt.show()

特别注意z变量.如果 z 不是多维的,则会抛出错误.

Take special note of the z variable. If z is not multidimensional, it will throw an error.

希望它可以解决您的问题

这篇关于axes3d.plot_wireframe(X,Y,Z)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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