本文主要演示如何使用matplotlib绘制三维图形
代码如下:
# -*- coding: UTF-8 -*-import matplotlib as mplfrom mpl_toolkits.mplot3d import Axes3Dimport numpy as npimport matplotlib.pyplot as plt# 设置图例字号mpl.rcParams['legend.fontsize'] = 10fig = plt.figure()# 设置三维图形模式ax = fig.gca(projection='3d')# 测试数据theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)z = np.linspace(-4, 4, 100) / 4r = z**3 + 1x = r * np.sin(theta)y = r * np.cos(theta)# 绘制图形ax.plot(x, y, z, label='parametric curve')# 显示图例ax.legend()# 显示图形plt.show()
运行效果