matplotlib图片显示

import matplotlib.pyplot as plt
import numpy as np

用array假装有一张9个像素点的图片

a = np.array([0.333333333, 0.366666666, 0.422222222,
              0.366666666, 0.433333333, 0.522222222,
              0.422222222, 0.522222222, 0.651555555]).reshape(3, 3)

interpolation-----模糊方式?还有很多参数
cmap-----颜色图谱
origin-----选upper就跟上面像素点的顺序一致,lower就倒过来

plt.imshow(a, interpolation='nearest', cmap='bone', origin='upper')

旁边的colorbar,其实还有很多参数,shrink是放缩比例

plt.colorbar(shrink=0.8)
plt.xticks(())
plt.yticks(())
plt.show()

在这里插入图片描述

那么怎么画3D的图像呢
首先引入

from mpl_toolkits.mplot3d import Axes3D

在figure中加入一个轴

fig = plt.figure()
ax = Axes3D(fig)

我们看看画出来的效果
在这里插入图片描述
具体例子
通过X,Y算出Z

fig = plt.figure()
ax = Axes3D(fig)
X = np.arange(-4, 4, 0.25)
Y = np.arange(-4, 4, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)

rstride,cstride------一个网格的长宽,可以自己改变着看一下
zdir=‘z’----向z投影

ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=plt.get_cmap('rainbow'))
ax.contourf(X, Y, Z, zdir='z', offset=-2, cmap='rainbow')
ax.set_zlim(-2, 2)
plt.show()

在这里插入图片描述

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值