python绘制二维图形_matplotlib从x、y、z值绘制二维图

问题是imshow(z_list, ...)将期望z_list是一个(n,m)类型的数组,基本上是一个值网格。要使用imshow函数,需要为每个网格点设置Z值,可以通过收集更多数据或插值来实现。

下面是一个将数据与线性插值结合使用的示例:from scipy.interpolate import interp2d

# f will be a function with two arguments (x and y coordinates),

# but those can be array_like structures too, in which case the

# result will be a matrix representing the values in the grid

# specified by those arguments

f = interp2d(x_list,y_list,z_list,kind="linear")

x_coords = np.arange(min(x_list),max(x_list)+1)

y_coords = np.arange(min(y_list),max(y_list)+1)

Z = f(x_coords,y_coords)

fig = plt.imshow(Z,

extent=[min(x_list),max(x_list),min(y_list),max(y_list)],

origin="lower")

# Show the positions of the sample points, just to have some reference

fig.axes.set_autoscale_on(False)

plt.scatter(x_list,y_list,400,facecolors='none')

您可以看到它在您的采样点处显示正确的值(由x_list和y_list指定,由半圆表示),但由于插值的性质和采样点的数量较少,它在其他位置的变化要大得多。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值