1. 程式人生 > 其它 >python中3D影象的繪製

python中3D影象的繪製

技術標籤:pythonpython

1、二維正態分佈繪製

1、描述
  繪製三維影象-二元類正態分佈(mu,sigma^2)=(0,1)。

  在顯示影象時,有下面的一下引數資訊可以配置,比如:maker的描述資訊:

 # marker	description
    # ”.”	point
    # ”,”	pixel
    # “o”	circle
    # “v”	triangle_down
    # “^”	triangle_up
    # “<”	triangle_left
    # “>”	triangle_right
    # “1”	tri_down
# “2” tri_up # “3” tri_left # “4” tri_right # “8” octagon # “s” square # “p” pentagon # “*” star # “h” hexagon1 # “H” hexagon2 # “+” plus # “x” x # “D” diamond # “d” thin_diamond # “|” vline # “_” hline # TICKLEFT tickleft # TICKRIGHT tickright
# TICKUP tickup # TICKDOWN tickdown # CARETLEFT caretleft # CARETRIGHT caretright # CARETUP caretup # CARETDOWN caretdown

  著色方案的引數設定:

cmaps = [('Perceptually Uniform Sequential',
          ['viridis', 'inferno', 'plasma', 'magma']),
         ('Sequential', ['Blues', 'BuGn'
, 'BuPu', 'GnBu', 'Greens', 'Greys', 'Oranges', 'OrRd', 'PuBu', 'PuBuGn', 'PuRd', 'Purples', 'RdPu', 'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd']), ('Sequential (2)', ['afmhot', 'autumn', 'bone', 'cool', 'copper', 'gist_heat', 'gray', 'hot', 'pink', 'spring', 'summer', 'winter']), ('Diverging', ['BrBG', 'bwr', 'coolwarm', 'PiYG', 'PRGn', 'PuOr', 'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn', 'Spectral', 'seismic']), ('Qualitative', ['Accent', 'Dark2', 'Paired', 'Pastel1', 'Pastel2', 'Set1', 'Set2', 'Set3']), ('Miscellaneous', ['gist_earth', 'terrain', 'ocean', 'gist_stern', 'brg', 'CMRmap', 'cubehelix', 'gnuplot', 'gnuplot2', 'gist_ncar', 'nipy_spectral', 'jet', 'rainbow', 'gist_rainbow', 'hsv', 'flag', 'prism'])]

2、程式碼

# @Time : 2020/12/8 17:31
# @Description : 繪製三維影象-二元類正態分佈(mu,sigma^2)=(0,1)
import math
import numpy as np
import matplotlib as mpl
from matplotlib import cm
import matplotlib.pyplot as plt

x, y = np.ogrid[-3:3:100j, -3:3:100j]
# 下面的兩行程式碼和上面程式碼等價
# u = np.linspace(-3, 3, 101)
# x, y = np.meshgrid(u, u)
# x * y 乘到下面的函式中,會有正負交替影象的出現。
z = x * y * np.exp(-(x ** 2 + y ** 2) / 2) / math.sqrt(2 * math.pi)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# cmap著色方案
# rstride=5, cstride=5:橫軸縱軸有101個點我們每5個取一個點。數值越小,圖形顯示越密集。
ax.plot_surface(x, y, z, rstride=5, cstride=5, cmap=cm.Accent, linewidth=0.5)
plt.show()

結果展示: