国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

python matplotlib繪制三維圖的示例

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

作者:catmelo 本文版權歸作者所有

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

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

起步

新建一個matplotlib.figure.Figure對象,然后向其添加一個Axes3D類型的axes對象。其中Axes3D對象的創建,類似其他axes對象,只不過使用projection=’3d’關鍵詞。

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()

簡化用法:

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’) #無法使用

3D散點圖

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繪制三維圖的示例的詳細內容,更多關于matplotlib繪制三維圖的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 广平县| 宾阳县| 新安县| 故城县| 如皋市| 班玛县| 蛟河市| 天全县| 西华县| 马公市| 利辛县| 贵德县| 南昌市| 香港| 雷州市| 北安市| 水城县| 蒙城县| 梁平县| 昌乐县| 莱芜市| 双江| 景洪市| 岫岩| 新乡县| 兴城市| 深圳市| 南昌市| 东兴市| 邵阳县| 柘城县| 东乡族自治县| 会东县| 容城县| 咸阳市| 龙胜| 彭水| 新巴尔虎左旗| 鹿泉市| 台山市| 阳谷县|