Python中的图形绘制——3D绘图

在 matplotlib 中可以轻松绘制 3D 图形。 接下来讨论一些重要且常用的 3D 图。

1 ​ 画点代码

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


# setting a custom style to use
style.use('ggplot')


# create a new figure for plotting
fig = plt.figure()


# create a new subplot on our figure
# and set projection as 3d
ax1 = fig.add_subplot(111, projection='3d')
ax1.scatter(x, y, z, c = 'm', marker = 'o')


# defining x, y, z co-ordinates
x = np.random.randint(0, 10, size = 20)
y = np.random.randint(0, 10, size = 20)
z = np.random.randint(0, 10, size = 20)


# plotting the points on subplot




# setting labels for the axes
ax1.set_xlabel('x-axis')
ax1.set_ylabel('y-axis')
ax1.set_zlabel('z-axis')


# function to show the plot
plt.show()

2 ​ 输出

上述程序的输出将为您提供一个可以旋转或放大绘图的窗口。 这是屏幕截图ÿ

  • 6
    点赞
  • 55
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值