最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python?繪制3D圖案例分享

 更新時間:2022年07月31日 14:58:13   作者:憑軒聽雨199407  
這篇文章主要介紹了python?繪制3D圖案例分享,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下,希望對你的學(xué)習(xí)有所幫助

1.散點(diǎn)圖

代碼

# This import registers the 3D projection, but is otherwise unused.
from mpl_toolkits.mplot3d import Axes3D  # noqa: F401 unused import

import matplotlib.pyplot as plt
import numpy as np

# Fixing random state for reproducibility
np.random.seed(19680801)
def 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) + vmin

fig = 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 m, zlow, zhigh in [('o', -50, -25), ('^', -30, -5)]:
    xs = randrange(n, 23, 32)
    ys = randrange(n, 0, 100)
    zs = randrange(n, zlow, zhigh)
    ax.scatter(xs, ys, zs, marker=m)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show()

輸出:

輸入的數(shù)據(jù)格式

這個輸入的三個維度要求是三列長度一致的數(shù)據(jù),可以理解為3個length相等的list。
用上面的scatter或者下面這段直接plot也可以。

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot(h, z, t, '.', alpha=0.5)
plt.show()

輸出:

2.三維表面 surface

代碼

x = [12.7, 12.8, 12.9]
y = [1, 2, 3, 4]
temp = pd.DataFrame([[7,7,9,9],[2,3,4,5],[1,6,8,7]]).T
X,Y = np.meshgrid(x,y)  # 形成網(wǎng)格化的數(shù)據(jù)
temp = np.array(temp)
fig = plt.figure(figsize=(16, 16))
ax = fig.gca(projection='3d')
ax.plot_surface(Y,X,temp,rcount=1, cmap=cm.plasma, linewidth=1, antialiased=False,alpha=0.5) #cm.plasma
ax.set_xlabel('zone', color='b', fontsize=20)
ax.set_ylabel('h2o', color='g', fontsize=20)
ax.set_zlabel('Temperature', color='r', fontsize=20)

output:

輸入的數(shù)據(jù)格式

這里x和y原本都是一維list,通過np.meshgrid可以將其形成4X3的二維數(shù)據(jù),如下圖所示:

而第三維,得是4X3的2維的數(shù)據(jù),才能進(jìn)行畫圖

scatter + surface圖形展示

3. 三維瀑布圖waterfall

代碼

from matplotlib.collections import PolyCollection
import matplotlib.pyplot as plt
from matplotlib import colors as mcolors
import numpy as np

axes=plt.axes(projection="3d")

def colors(arg):
    return mcolors.to_rgba(arg, alpha=0.6)
verts = []
z1 = [1, 2, 3, 4]
x1 = np.arange(0, 10, 0.4)
for z in z1:
    y1 = np.random.rand(len(x1))
    y1[0], y1[-1] = 0, 0
    verts.append(list(zip(x1, y1)))
# print(verts)
poly = PolyCollection(verts, facecolors=[colors('r'), colors('g'), colors('b'),
                                         colors('y')])
poly.set_alpha(0.7)
axes.add_collection3d(poly, zs=z1, zdir='y')
axes.set_xlabel('X')
axes.set_xlim3d(0, 10)
axes.set_ylabel('Y')
axes.set_ylim3d(-1, 4)
axes.set_zlabel('Z')
axes.set_zlim3d(0, 1)
axes.set_title("3D Waterfall plot")
plt.show()

輸出:

輸入的數(shù)據(jù)格式

這個的輸入我還沒有完全搞懂,導(dǎo)致我自己暫時不能復(fù)現(xiàn)到其他數(shù)據(jù),等以后懂了再回來補(bǔ)充。

4. 3d wireframe

code

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

fig, (ax1, ax2) = plt.subplots(
    2, 1, figsize=(8, 12), subplot_kw={'projection': '3d'})

# Get the test data
X, Y, Z = axes3d.get_test_data(0.05)

# Give the first plot only wireframes of the type y = c
ax1.plot_wireframe(X, Y, Z, rstride=10, cstride=0)
ax1.set_title("Column (x) stride set to 0")

# Give the second plot only wireframes of the type x = c
ax2.plot_wireframe(X, Y, Z, rstride=0, cstride=10)
ax2.set_title("Row (y) stride set to 0")
plt.tight_layout()
plt.show()

output:

輸入的數(shù)據(jù)格式

與plot_surface的輸入格式一樣,X,Y原本為一維list,通過np.meshgrid形成網(wǎng)格化數(shù)據(jù)。Z為二維數(shù)據(jù)。其中注意調(diào)節(jié)rstride、cstride這兩個值實(shí)現(xiàn)行列間隔的調(diào)整。

自己試了下:

到此這篇關(guān)于python 繪制3D圖案例分享的文章就介紹到這了,更多相關(guān)python 繪制3D圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python Loguru輕松靈活的日志管理庫基本用法探索

    Python Loguru輕松靈活的日志管理庫基本用法探索

    Loguru是一個用于Python的高性能、簡潔且靈活的日志庫,它的目標(biāo)是提供一種簡單的方式來記錄應(yīng)用程序的運(yùn)行情況,同時保持代碼的簡潔性和可讀性,本文將探索loguru的基本用法
    2024-01-01
  • python with (as)語句實(shí)例詳解

    python with (as)語句實(shí)例詳解

    這篇文章主要介紹了python with (as)語句實(shí)例詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-02-02
  • Python如何用字典完成匹配任務(wù)

    Python如何用字典完成匹配任務(wù)

    在生物信息學(xué)領(lǐng)域,經(jīng)常需要根據(jù)基因名稱匹配其對應(yīng)的編號,本文介紹了一種通過字典進(jìn)行基因名稱與編號匹配的方法,首先定義一個空列表存儲對應(yīng)編號,對于字典中不存在的基因名稱,其編號默認(rèn)為0
    2024-09-09
  • 詳解python中*號的用法

    詳解python中*號的用法

    這篇文章主要介紹了python中*號的用法,文中通過代碼給大家介紹了雙星號(**)的用法,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-10-10
  • flask-SQLALchemy連接數(shù)據(jù)庫的實(shí)現(xiàn)示例

    flask-SQLALchemy連接數(shù)據(jù)庫的實(shí)現(xiàn)示例

    sqlalchemy是數(shù)據(jù)庫的orm框架,讓我們操作數(shù)據(jù)庫的時候不要再用sql語句了,本文就介紹了flask-SQLALchemy連接數(shù)據(jù)庫的實(shí)現(xiàn)示例,感興趣的可以了解一下
    2022-06-06
  • 分享13個好用到起飛的Python技巧

    分享13個好用到起飛的Python技巧

    編程是有技巧的,能寫的出程序的人很多,但能寫的又快又好是有技巧的,下面這篇文章主要給大家介紹了13個好用到起飛的Python技巧,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2021-10-10
  • 詳解Python中@staticmethod和@classmethod區(qū)別及使用示例代碼

    詳解Python中@staticmethod和@classmethod區(qū)別及使用示例代碼

    這篇文章主要介紹了詳解Python中@staticmethod和@classmethod區(qū)別及使用示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • 詳解Python中的文件操作

    詳解Python中的文件操作

    這篇文章主要介紹了Python中文件操作的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)python,感興趣的朋友可以了解下
    2021-01-01
  • Python bsonrpc源碼解讀

    Python bsonrpc源碼解讀

    這篇文章主要介紹了Python bsonrpc源碼的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下
    2021-03-03
  • Django中QuerySet查詢優(yōu)化之prefetch_related詳解

    Django中QuerySet查詢優(yōu)化之prefetch_related詳解

    prefetch_related()和select_related()的設(shè)計(jì)目的很相似,都是為了減少SQL查詢的數(shù)量,但是實(shí)現(xiàn)的方式不一樣,下面這篇文章主要給大家介紹了關(guān)于Django中QuerySet查詢優(yōu)化之prefetch_related的相關(guān)資料,需要的朋友可以參考下
    2022-11-11

最新評論

静乐县| 桑植县| 张家界市| 诸暨市| 浦县| 固原市| 永清县| 江华| 德惠市| 漳州市| 兰考县| 龙江县| 墨脱县| 西华县| 滦平县| 仙桃市| 迁安市| 平远县| 昭苏县| 石门县| 蓝田县| 陆河县| 泽库县| 林口县| 福海县| 化德县| 英山县| 元谋县| 永泰县| 紫阳县| 工布江达县| 西林县| 中卫市| 灌云县| 赤水市| 正宁县| 哈尔滨市| 昌宁县| 榆树市| 连云港市| 梁平县|