python中3D图像的绘制

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

结果展示:
python中3D图像的绘制

上一篇:利用生成器输出杨辉三角


下一篇:[LeetCode] 118. 杨辉三角