ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

【python】matplotlib画3D图

2022-07-28 18:06:26  阅读:196  来源: 互联网

标签:figure python matplotlib np add fig Axes3D ax 3D


画点:

点击查看代码
from matplotlib import pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
 
x = np.random.rand(100)
y = np.random.rand(100)
z = np.random.rand(100)
 
fig = plt.figure()
ax = Axes3D(fig, auto_add_to_figure=False)
fig.add_axes(ax)
 
ax.scatter(x,y,z,s=10,color="r",marker='o')
 
plt.show()

画线:

点击查看代码
from matplotlib import pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
 
zline = np.linspace(0,15,1000)
xline = np.sin(zline)
yline = np.cos(zline)
 
fig = plt.figure()
ax = Axes3D(fig, auto_add_to_figure=False)
fig.add_axes(ax)
 
ax.plot(xline,yline,zline)
 
plt.show()

关于ax = Axes3D(fig)的警告:/var/folders/y1/x8ktr6kd0jz8dms037zl0_t00000gn/T/ipykernel_83156/2478856790.py:1: MatplotlibDeprecationWarning: Axes3D(fig) adding itself to the figure is deprecated since 3.4. Pass the keyword argument auto_add_to_figure=False and use fig.add_axes(ax) to suppress this warning. The default value of auto_add_to_figure will change to False in mpl3.5 and True values will no longer work in 3.6. This is consistent with other Axes classes.

改成下述版本
ax = Axes3D(fig, auto_add_to_figure=False)
fig.add_axes(ax)

在控制台中逐行运行代码,不报错也不显示图片的解决办法:

下述代码不能在控制台中分开,要写在一起运行
fig = plt.figure()
ax = Axes3D(fig, auto_add_to_figure=False)
fig.add_axes(ax)

写成图中形式会报错

标签:figure,python,matplotlib,np,add,fig,Axes3D,ax,3D
来源: https://www.cnblogs.com/xyq-deeplearning/p/16529639.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有