久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python matplotlib繪制三維圖的示例

瀏覽:3日期:2022-07-10 09:52:12

作者:catmelo 本文版權(quán)歸作者所有

鏈接:https://www.cnblogs.com/catmelo/p/4162101.html

本文參考官方文檔:http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html

起步

新建一個(gè)matplotlib.figure.Figure對(duì)象,然后向其添加一個(gè)Axes3D類(lèi)型的axes對(duì)象。其中Axes3D對(duì)象的創(chuàng)建,類(lèi)似其他axes對(duì)象,只不過(guò)使用projection=’3d’關(guān)鍵詞。

import matplotlib.pyplot as pltfrom mpl_toolkits.mplot3d import Axes3Dfig = plt.figure()ax = fig.add_subplot(111, projection=’3d’)

3D曲線圖

python matplotlib繪制三維圖的示例

import matplotlib as mplfrom mpl_toolkits.mplot3d import Axes3Dimport numpy as npimport matplotlib.pyplot as pltmpl.rcParams[’legend.fontsize’] = 10fig = plt.figure()ax = fig.gca(projection=’3d’)theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)z = np.linspace(-2, 2, 100)r = z**2 + 1x = r * np.sin(theta)y = r * np.cos(theta)ax.plot(x, y, z, label=’parametric curve’)ax.legend()ax.set_xlabel(’X Label’)ax.set_ylabel(’Y Label’)ax.set_zlabel(’Z Label’)plt.show()

簡(jiǎn)化用法:

python matplotlib繪制三維圖的示例

from pylab import *from mpl_toolkits.mplot3d import Axes3Dplt.gca(projection=’3d’)plt.plot([1,2,3],[3,4,1],[8,4,1],’--’)plt.xlabel(’X’)plt.ylabel(’Y’)#plt.zlabel(’Z’) #無(wú)法使用

3D散點(diǎn)圖

python matplotlib繪制三維圖的示例

import numpy as npfrom mpl_toolkits.mplot3d import Axes3Dimport matplotlib.pyplot as pltdef randrange(n, vmin, vmax): return (vmax-vmin)*np.random.rand(n) + vminfig = plt.figure()ax = fig.add_subplot(111, projection=’3d’)n = 100for c, m, zl, zh in [(’r’, ’o’, -50, -25), (’b’, ’^’, -30, -5)]: xs = randrange(n, 23, 32) ys = randrange(n, 0, 100) zs = randrange(n, zl, zh) ax.scatter(xs, ys, zs, c=c, marker=m)ax.set_xlabel(’X Label’)ax.set_ylabel(’Y Label’)ax.set_zlabel(’Z Label’)plt.show()

以上就是matplotlib繪制三維圖的示例的詳細(xì)內(nèi)容,更多關(guān)于matplotlib繪制三維圖的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 茌平县| 商都县| 河西区| 海安县| 富宁县| 甘洛县| 黄平县| 信宜市| 楚雄市| 阿拉尔市| 丁青县| 龙井市| 广元市| 福泉市| 新蔡县| 从江县| 顺昌县| 泊头市| 上林县| 五指山市| 丹寨县| 新兴县| 科技| 大埔区| 辽源市| 井冈山市| 盐亭县| 武穴市| 麦盖提县| 怀仁县| 拜泉县| 慈溪市| 天镇县| 麻阳| 顺平县| 宜州市| 金川县| 镇平县| 托克托县| 北流市| 准格尔旗|