日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python科学坐标图绘制的四个要素_Python3.0科学计算学习之绘图(四)

發(fā)布時間:2025/3/15 python 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python科学坐标图绘制的四个要素_Python3.0科学计算学习之绘图(四) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

繪制三維圖:

mplot3d工具包提供了點、線、等值線、曲面和所有其他基本組件以及三維旋轉縮放的三維繪圖。

1.散點的三維數(shù)據(jù)圖

from mpl_toolkits.mplot3d import axes3d? ? ? ? ? ? ? ? ? ? #需要從mplot3d模塊中導入axes 3D類型

import numpy as np

import matplotlib.pyplot as plt

fig=plt.figure()

ax=fig.gca(projection='3d')? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #通過將關鍵字projection='3d'應用到坐標軸對象上來實現(xiàn)三維繪圖

class1=0.6*np.random.standard_normal((200,3))

ax.plot(class1[:,0],class1[:,1],class1[:,2],'o')

class2=1.2*np.random.standard_normal((200,3))+np.array([5,4,0])

ax.plot(class2[:,0],class2[:,1],class2[:,2],'o')

class3=0.3*np.random.standard_normal((200,3))+np.array([0,3,2])

ax.plot(class3[:,0],class3[:,1],class3[:,2],'o')

2. 表面圖(Surface plots)

基本用法:ax.plot_surface(X,Y,Z,alpha=0.5)

X,Y,Z:數(shù)據(jù)color:表明顏色cmap:圖層

示例:

from mpl_toolkits.mplot3d import axes3d

import numpy as np

import matplotlib.pyplot as plt

fig=plt.figure()

ax=fig.gca(projection='3d')

X,Y,Z=axes3d.get_test_data(0.05)

ax.plot_surface(X,Y,Z,alpha=0.5)

3. 線框圖(Wireframe plots)

基本用法:ax.plot_wireframe(X, Y, Z,?*args,?**kwargs)

X,Y,Z:輸入數(shù)據(jù)

rstride:行步長

cstride:列步長

rcount:行數(shù)上限

ccount:列數(shù)上限

示例:

from mpl_toolkits.mplot3d import axes3d

import matplotlib.pyplot as plt

fig=plt.figure()

ax=fig.gca(projection='3d')

X,Y,Z=axes3d.get_test_data(0.05)

ax.plot_wireframe(X,Y,Z,rstride=5,cstride=5)

ax.contour(X,Y,Z,zdir='z',offset=-100)? ? ? ? ? ? ? #等高線

ax.contour(X,Y,Z,zdir='x',offset=-40)

ax.contour(X,Y,Z,zdir='y',offset=40)

ax.set_xlim3d(-40,40)? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #設置坐標軸極限的標準

ax.set_ylim3d(-40,40)

ax.set_zlim3d(-100,100)

ax.set_xlabel('X axis')? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #設置標簽的命令

ax.set_ylabel('Y axis')

ax.set_zlabel('Z axis')

#結果圖:

4. 散點繪制(Scatter plots)

基本用法:ax.scatter(xs, ys, zs, s=20, c=None, depthshade=True,?*args,?*kwargs)

xs,ys,zs:輸入數(shù)據(jù);

s:scatter點的尺寸

c:顏色,如c = 'r'就是紅色;

depthshase:透明化,True為透明,默認為True,False為不透明

*args等為擴展變量,如maker = 'o',則scatter結果為’o‘的形狀

示例:

from mpl_toolkits.mplot3d import Axes3D

import matplotlib.pyplot as plt

import numpy as np

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

#結果圖如下:

5.條形圖(Bar plots)

基本方法:ax.bar(left, height, zs=0, zdir='z',?*args,?**kwargs

x,y,zs = z,數(shù)據(jù)

zdir:條形圖平面化的方向,具體可以對應代碼理解

示例:

from mpl_toolkits.mplot3d import Axes3D

import matplotlib.pyplot as plt

import numpy as np

fig = plt.figure()

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

for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]):

xs = np.arange(20)

ys = np.random.rand(20)

cs = [c] * len(xs)

cs[0] = 'c'

ax.bar(xs, ys, zs=z, zdir='y', color=cs, alpha=0.8)

ax.set_xlabel('X')

ax.set_ylabel('Y')

ax.set_zlabel('Z')

plt.show() ???#結果圖:

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結

以上是生活随笔為你收集整理的python科学坐标图绘制的四个要素_Python3.0科学计算学习之绘图(四)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。