亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

python (matplotlib)畫三維圖像

系統(tǒng) 2947 0

關(guān)于三維圖像的內(nèi)容很多博友已經(jīng)寫了
推薦:三維繪圖,畫三維圖,3d圖-英文版
上面寫的都非常詳細(xì),很推薦,特別是英文版那個(gè),基于此,只給我寫的一個(gè)例子

三維圖

f ( x , y ) = x 2 + y 2 f(x,y)=x^2+y^2 f ( x , y ) = x 2 + y 2 的三維圖
python (matplotlib)畫三維圖像_第1張圖片

            
              
                import
              
               numpy 
              
                as
              
               np

              
                import
              
               matplotlib
              
                .
              
              pyplot 
              
                as
              
               plt

              
                from
              
               mpl_toolkits
              
                .
              
              mplot3d 
              
                import
              
               Axes3D

x 
              
                =
              
               np
              
                .
              
              arange
              
                (
              
              
                -
              
              
                10
              
              
                ,
              
              
                10
              
              
                ,
              
              
                0.2
              
              
                )
              
              
y 
              
                =
              
               np
              
                .
              
              arange
              
                (
              
              
                -
              
              
                10
              
              
                ,
              
              
                10
              
              
                ,
              
              
                0.2
              
              
                )
              
              
f_x_y
              
                =
              
              np
              
                .
              
              power
              
                (
              
              x
              
                ,
              
              
                2
              
              
                )
              
              
                +
              
              np
              
                .
              
              power
              
                (
              
              y
              
                ,
              
              
                2
              
              
                )
              
              
fig 
              
                =
              
               plt
              
                .
              
              figure
              
                (
              
              
                )
              
              
ax 
              
                =
              
               plt
              
                .
              
              gca
              
                (
              
              projection
              
                =
              
              
                '3d'
              
              
                )
              
              
ax
              
                .
              
              plot
              
                (
              
              x
              
                ,
              
              y
              
                ,
              
              f_x_y
              
                )
              
            
          

畫出2維不相關(guān)高斯分布的3維圖,即下面公式中n=2的情況
python (matplotlib)畫三維圖像_第2張圖片
python (matplotlib)畫三維圖像_第3張圖片

            
              
                import
              
               numpy 
              
                as
              
               np

              
                import
              
               matplotlib
              
                .
              
              pyplot 
              
                as
              
               plt

              
                import
              
               mpl_toolkits
              
                .
              
              axisartist 
              
                as
              
               axisartist

              
                from
              
               mpl_toolkits
              
                .
              
              mplot3d 
              
                import
              
               Axes3D 
              
                #畫三維圖不可少
              
              
                from
              
               matplotlib 
              
                import
              
               cm  
              
                #cm 是colormap的簡(jiǎn)寫
              
              
                # 1_dimension gaussian function
              
              
                def
              
              
                gaussian
              
              
                (
              
              x
              
                ,
              
              mu
              
                ,
              
              sigma
              
                )
              
              
                :
              
              
    f_x 
              
                =
              
              
                1
              
              
                /
              
              
                (
              
              sigma
              
                *
              
              np
              
                .
              
              sqrt
              
                (
              
              
                2
              
              
                *
              
              np
              
                .
              
              pi
              
                )
              
              
                )
              
              
                *
              
              np
              
                .
              
              exp
              
                (
              
              
                -
              
              np
              
                .
              
              power
              
                (
              
              x
              
                -
              
              mu
              
                ,
              
              
                2
              
              
                .
              
              
                )
              
              
                /
              
              
                (
              
              
                2
              
              
                *
              
              np
              
                .
              
              power
              
                (
              
              sigma
              
                ,
              
              
                2
              
              
                .
              
              
                )
              
              
                )
              
              
                )
              
              
                return
              
              
                (
              
              f_x
              
                )
              
              
                # 2_dimension gaussian function
              
              
                def
              
              
                gaussian_2
              
              
                (
              
              x
              
                ,
              
              y
              
                ,
              
              mu_x
              
                ,
              
              mu_y
              
                ,
              
              sigma_x
              
                ,
              
              sigma_y
              
                )
              
              
                :
              
              
    f_x_y 
              
                =
              
              
                1
              
              
                /
              
              
                (
              
              sigma_x
              
                *
              
              sigma_y
              
                *
              
              
                (
              
              np
              
                .
              
              sqrt
              
                (
              
              
                2
              
              
                *
              
              np
              
                .
              
              pi
              
                )
              
              
                )
              
              
                **
              
              
                2
              
              
                )
              
              
                *
              
              np
              
                .
              
              exp
              
                (
              
              
                -
              
              np
              
                .
              
              power\
              
              
                (
              
              x
              
                -
              
              mu_x
              
                ,
              
              
                2
              
              
                .
              
              
                )
              
              
                /
              
              
                (
              
              
                2
              
              
                *
              
              np
              
                .
              
              power
              
                (
              
              sigma_x
              
                ,
              
              
                2
              
              
                .
              
              
                )
              
              
                )
              
              
                -
              
              np
              
                .
              
              power
              
                (
              
              y
              
                -
              
              mu_y
              
                ,
              
              
                2
              
              
                .
              
              
                )
              
              
                /
              
              \
              
              
                (
              
              
                2
              
              
                *
              
              np
              
                .
              
              power
              
                (
              
              sigma_y
              
                ,
              
              
                2
              
              
                .
              
              
                )
              
              
                )
              
              
                )
              
              
                return
              
              
                (
              
              f_x_y
              
                )
              
              
                #設(shè)置2維表格
              
              
x_values 
              
                =
              
               np
              
                .
              
              linspace
              
                (
              
              
                -
              
              
                5
              
              
                ,
              
              
                5
              
              
                ,
              
              
                2000
              
              
                )
              
              
y_values 
              
                =
              
               np
              
                .
              
              linspace
              
                (
              
              
                -
              
              
                5
              
              
                ,
              
              
                5
              
              
                ,
              
              
                2000
              
              
                )
              
              
X
              
                ,
              
              Y 
              
                =
              
               np
              
                .
              
              meshgrid
              
                (
              
              x_values
              
                ,
              
              y_values
              
                )
              
              
                #高斯函數(shù)
              
              
mu_x
              
                ,
              
              mu_y
              
                ,
              
              sigma_x
              
                ,
              
              sigma_y 
              
                =
              
              
                0
              
              
                ,
              
              
                0
              
              
                ,
              
              
                0.8
              
              
                ,
              
              
                0.8
              
              
F_x_y 
              
                =
              
               gaussian_2
              
                (
              
              X
              
                ,
              
              Y
              
                ,
              
              mu_x
              
                ,
              
              mu_y
              
                ,
              
              sigma_x
              
                ,
              
              sigma_y
              
                )
              
              
                #顯示三維圖
              
              
fig 
              
                =
              
               plt
              
                .
              
              figure
              
                (
              
              
                )
              
              
ax 
              
                =
              
               plt
              
                .
              
              gca
              
                (
              
              projection
              
                =
              
              
                '3d'
              
              
                )
              
              
ax
              
                .
              
              plot_surface
              
                (
              
              X
              
                ,
              
              Y
              
                ,
              
              F_x_y
              
                ,
              
              cmap
              
                =
              
              
                'jet'
              
              
                )
              
              
                # 顯示等高線圖
              
              
                #ax.contour3D(X,Y,F_x_y,50,cmap='jet')
              
            
          

三維等高線

將上面等高線打開,三維圖注釋掉

            
              
                #ax.plot_surface(X,Y,F_x_y,cmap='jet')
              
              
                # 顯示等高線圖
              
              
ax
              
                .
              
              contour3D
              
                (
              
              X
              
                ,
              
              Y
              
                ,
              
              F_x_y
              
                ,
              
              
                50
              
              
                ,
              
              cmap
              
                =
              
              
                'jet'
              
              
                )
              
            
          

python (matplotlib)畫三維圖像_第4張圖片

2維等高線

將上面的圖截取截面就是2維平面,是一個(gè)個(gè)圓形
python (matplotlib)畫三維圖像_第5張圖片

            
              
                import
              
               numpy 
              
                as
              
               np

              
                import
              
               matplotlib
              
                .
              
              pyplot 
              
                as
              
               plt

              
                import
              
               mpl_toolkits
              
                .
              
              axisartist 
              
                as
              
               axisartist

              
                from
              
               mpl_toolkits
              
                .
              
              mplot3d 
              
                import
              
               Axes3D 
              
                #畫三維圖不可少
              
              
                from
              
               matplotlib 
              
                import
              
               cm  
              
                #cm 是colormap的簡(jiǎn)寫
              
              
                #定義坐標(biāo)軸函數(shù)
              
              
                def
              
              
                setup_axes
              
              
                (
              
              fig
              
                ,
              
               rect
              
                )
              
              
                :
              
              
    ax 
              
                =
              
               axisartist
              
                .
              
              Subplot
              
                (
              
              fig
              
                ,
              
               rect
              
                )
              
              
    fig
              
                .
              
              add_axes
              
                (
              
              ax
              
                )
              
              

    ax
              
                .
              
              set_ylim
              
                (
              
              
                -
              
              
                4
              
              
                ,
              
              
                4
              
              
                )
              
              
                #自定義刻度
              
              
                #    ax.set_yticks([-10, 0,9])
              
              
    ax
              
                .
              
              set_xlim
              
                (
              
              
                -
              
              
                4
              
              
                ,
              
              
                4
              
              
                )
              
              
    ax
              
                .
              
              axis
              
                [
              
              
                :
              
              
                ]
              
              
                .
              
              set_visible
              
                (
              
              
                False
              
              
                )
              
              
                #第2條線,即y軸,經(jīng)過x=0的點(diǎn)
              
              
    ax
              
                .
              
              axis
              
                [
              
              
                "y"
              
              
                ]
              
              
                =
              
               ax
              
                .
              
              new_floating_axis
              
                (
              
              
                1
              
              
                ,
              
              
                0
              
              
                )
              
              
    ax
              
                .
              
              axis
              
                [
              
              
                "y"
              
              
                ]
              
              
                .
              
              set_axisline_style
              
                (
              
              
                "-|>"
              
              
                ,
              
               size
              
                =
              
              
                1.5
              
              
                )
              
              
                #    第一條線,x軸,經(jīng)過y=0的點(diǎn)
              
              
    ax
              
                .
              
              axis
              
                [
              
              
                "x"
              
              
                ]
              
              
                =
              
               ax
              
                .
              
              new_floating_axis
              
                (
              
              
                0
              
              
                ,
              
              
                0
              
              
                )
              
              
    ax
              
                .
              
              axis
              
                [
              
              
                "x"
              
              
                ]
              
              
                .
              
              set_axisline_style
              
                (
              
              
                "-|>"
              
              
                ,
              
               size
              
                =
              
              
                1.5
              
              
                )
              
              
                return
              
              
                (
              
              ax
              
                )
              
              
                # 1_dimension gaussian function
              
              
                def
              
              
                gaussian
              
              
                (
              
              x
              
                ,
              
              mu
              
                ,
              
              sigma
              
                )
              
              
                :
              
              
    f_x 
              
                =
              
              
                1
              
              
                /
              
              
                (
              
              sigma
              
                *
              
              np
              
                .
              
              sqrt
              
                (
              
              
                2
              
              
                *
              
              np
              
                .
              
              pi
              
                )
              
              
                )
              
              
                *
              
              np
              
                .
              
              exp
              
                (
              
              
                -
              
              np
              
                .
              
              power
              
                (
              
              x
              
                -
              
              mu
              
                ,
              
              
                2
              
              
                .
              
              
                )
              
              
                /
              
              
                (
              
              
                2
              
              
                *
              
              np
              
                .
              
              power
              
                (
              
              sigma
              
                ,
              
              
                2
              
              
                .
              
              
                )
              
              
                )
              
              
                )
              
              
                return
              
              
                (
              
              f_x
              
                )
              
              
                # 2_dimension gaussian function
              
              
                def
              
              
                gaussian_2
              
              
                (
              
              x
              
                ,
              
              y
              
                ,
              
              mu_x
              
                ,
              
              mu_y
              
                ,
              
              sigma_x
              
                ,
              
              sigma_y
              
                )
              
              
                :
              
              
    f_x_y 
              
                =
              
              
                1
              
              
                /
              
              
                (
              
              sigma_x
              
                *
              
              sigma_y
              
                *
              
              
                (
              
              np
              
                .
              
              sqrt
              
                (
              
              
                2
              
              
                *
              
              np
              
                .
              
              pi
              
                )
              
              
                )
              
              
                **
              
              
                2
              
              
                )
              
              
                *
              
              np
              
                .
              
              exp
              
                (
              
              
                -
              
              np
              
                .
              
              power\
              
              
                (
              
              x
              
                -
              
              mu_x
              
                ,
              
              
                2
              
              
                .
              
              
                )
              
              
                /
              
              
                (
              
              
                2
              
              
                *
              
              np
              
                .
              
              power
              
                (
              
              sigma_x
              
                ,
              
              
                2
              
              
                .
              
              
                )
              
              
                )
              
              
                -
              
              np
              
                .
              
              power
              
                (
              
              y
              
                -
              
              mu_y
              
                ,
              
              
                2
              
              
                .
              
              
                )
              
              
                /
              
              \
              
              
                (
              
              
                2
              
              
                *
              
              np
              
                .
              
              power
              
                (
              
              sigma_y
              
                ,
              
              
                2
              
              
                .
              
              
                )
              
              
                )
              
              
                )
              
              
                return
              
              
                (
              
              f_x_y
              
                )
              
              
                #設(shè)置畫布
              
              
fig 
              
                =
              
               plt
              
                .
              
              figure
              
                (
              
              figsize
              
                =
              
              
                (
              
              
                8
              
              
                ,
              
              
                8
              
              
                )
              
              
                )
              
              
                #建議可以直接plt.figure()不定義大小
              
              
ax1 
              
                =
              
               setup_axes
              
                (
              
              fig
              
                ,
              
              
                111
              
              
                )
              
              
ax1
              
                .
              
              axis
              
                [
              
              
                "x"
              
              
                ]
              
              
                .
              
              set_axis_direction
              
                (
              
              
                "bottom"
              
              
                )
              
              
ax1
              
                .
              
              axis
              
                [
              
              
                'y'
              
              
                ]
              
              
                .
              
              set_axis_direction
              
                (
              
              
                'right'
              
              
                )
              
              
                #在已經(jīng)定義好的畫布上加入高斯函數(shù)
              
              
x_values 
              
                =
              
               np
              
                .
              
              linspace
              
                (
              
              
                -
              
              
                5
              
              
                ,
              
              
                5
              
              
                ,
              
              
                2000
              
              
                )
              
              
y_values 
              
                =
              
               np
              
                .
              
              linspace
              
                (
              
              
                -
              
              
                5
              
              
                ,
              
              
                5
              
              
                ,
              
              
                2000
              
              
                )
              
              
X
              
                ,
              
              Y 
              
                =
              
               np
              
                .
              
              meshgrid
              
                (
              
              x_values
              
                ,
              
              y_values
              
                )
              
              
mu_x
              
                ,
              
              mu_y
              
                ,
              
              sigma_x
              
                ,
              
              sigma_y 
              
                =
              
              
                0
              
              
                ,
              
              
                0
              
              
                ,
              
              
                0.8
              
              
                ,
              
              
                0.8
              
              
F_x_y 
              
                =
              
               gaussian_2
              
                (
              
              X
              
                ,
              
              Y
              
                ,
              
              mu_x
              
                ,
              
              mu_y
              
                ,
              
              sigma_x
              
                ,
              
              sigma_y
              
                )
              
              
                #顯示三維圖
              
              
                #fig = plt.figure()
              
              
                #ax = plt.gca(projection='3d')
              
              
                #ax.plot_surface(X,Y,F_x_y,cmap='jet')
              
              
                # 顯示3d等高線圖
              
              
                #ax.contour3D(X,Y,F_x_y,50,cmap='jet')
              
              
                # 顯示2d等高線圖,畫8條線
              
              
plt
              
                .
              
              contour
              
                (
              
              X
              
                ,
              
              Y
              
                ,
              
              F_x_y
              
                ,
              
              
                8
              
              
                )
              
            
          

更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!??!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: www.久草视频 | 羞羞视频在线免费 | 亚洲国产欧美在线不卡中文 | 91热视频在线 | 黄片毛片免费在线观看 | 四虎影院官网 | 国产一区二区三区高清视频 | 色久综合 | 亚洲精品高清国产麻豆专区 | 九一视频在线 | 韩国欧美一级毛片免费 | 98精品国产综合久久 | 亚洲色欲色欲www | 淫视频在线观看 | 四虎影院2022 | 色偷偷青青草原在线视频 | 久草在线资源网 | 久久9966精品国产免费 | 国内自拍青青草 | 国产第一综合另类色区奇米 | 精品伊人久久久 | 在线观看国产91 | 久久久精品日本一区二区三区 | 人人爰人人人人人鲁 | 日本黄页网| 中国国语毛片免费观看视频 | 成人91| 久久在精品线影院精品国产 | 天天操操操操操操 | 亚洲第一成年网 | 97在线观看中心 | 日本在线播放一区 | 日本乱中文字幕系列在线观看 | 免费视频网站一级人爱视频 | 国产精品一区二区三区久久 | 精品外国呦系列在线观看 | 伊人网站视频 | 黄色操视频| 日本一区二区三区高清福利视频 | 亚洲综合插插 | 免费观看欧美精品成人毛片 |