国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

matplotlib在python上繪制3D散點圖實例詳解

2020-02-16 11:01:30
字體:
來源:轉載
供稿:網友

大家可以先參考官方演示文檔:

效果圖:

'''==============3D scatterplot==============Demonstration of a basic scatterplot in 3D.'''from mpl_toolkits.mplot3d import Axes3Dimport matplotlib.pyplot as pltimport numpy as npdef randrange(n, vmin, vmax): ''' Helper function to make an array of random numbers having shape (n, ) with each number distributed Uniform(vmin, vmax). ''' return (vmax - vmin)*np.random.rand(n) + vminfig = plt.figure()ax = fig.add_subplot(111, projection='3d')n = 100# For each set of style and range settings, plot n random points in the box# defined by x in [23, 32], y in [0, 100], z in [zlow, zhigh].for c, m, zlow, zhigh in [('r', 'o', -50, -25), ('b', '^', -30, -5)]: xs = randrange(n, 23, 32) ys = randrange(n, 0, 100) zs = randrange(n, zlow, zhigh) 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()

以上是官網上的代碼示例及演示結果,下面分享下本文代碼示例。

本實例需要導入第三包:

import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D 

然后繪圖:

ax = plt.figure().add_subplot(111, projection = '3d') #基于ax變量繪制三維圖 #xs表示x方向的變量 #ys表示y方向的變量 #zs表示z方向的變量,這三個方向上的變量都可以用list的形式表示 #m表示點的形式,o是圓形的點,^是三角形(marker) #c表示顏色(color for short) ax.scatter(xs, ys, zs, c = 'r', marker = '^') #點為紅色三角形  #設置坐標軸 ax.set_xlabel('X Label') ax.set_ylabel('Y Label') ax.set_zlabel('Z Label')  #顯示圖像 plt.show() 

注:

上面的

ax = plt.figure().add_subplot(111, projection = '3d') 

是下面代碼的略寫

fig = plt.figure() ax = fig.add_subplot(111, projection = '3d') 

總結

以上就是本文關于matplotlib在python上繪制3D散點圖實例詳解的全部內容,希望對大家有所幫助。感興趣的朋友可以繼續參閱本站其他相關專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长岭县| 泸水县| 城固县| 丰镇市| 和政县| 丹阳市| 太康县| 包头市| 阜新市| 洛隆县| 新巴尔虎右旗| 巨鹿县| 韶关市| 五家渠市| 铜陵市| 潮州市| 田阳县| 灵台县| 天水市| 普兰店市| 乌兰察布市| 夏邑县| 天长市| 靖州| 射洪县| 遵义市| 徐水县| 仙桃市| 富裕县| 夹江县| 屏东市| 新沂市| 炎陵县| 延长县| 泊头市| 高平市| 富川| 平和县| 讷河市| 赫章县| 娄烦县|