具有来自单独 2D 数组的值的彩色 2D 网格 [英] Color 2D Grid with values from separate 2D array

查看:57
本文介绍了具有来自单独 2D 数组的值的彩色 2D 网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数据数组,x和y.我想绘制散点图 y 与 x.x的范围是[0,3],y的范围是[-3,3].然后,我想将此区域网格化为n×m的网格,并基于单独的2D numpy数组的值(与网格相同的形状,n×m)对每个区域中的点着色.因此,应该根据colorarr [0] [0]的值对图的最左上角的网格单元进行着色.有人对如何执行此操作有任何建议吗?到目前为止,我发现的最接近的是以下内容:

I have two arrays of data, x and y. I would like to plot on a scatter plot y vs. x. The range of x is [0,3] and the range of y is [-3, 3]. I then want to grid up this region into an n by m grid and color the points in each region based on the values of a separate 2D numpy array (same shape as the grid, n by m). So, the top-leftmost grid cell of my plot should be colored based on the value of colorarr[0][0] and so on. Anyone have any suggestions on how to do this? The closest I"ve found so far is the following:

Python中的2D网格数据可视化

不幸的是,这只是显示了色差,而不是我想可视化的2D区域.

Unfortunately this simply displays the colorarr, and not the 2D region I would like to visualize.

谢谢!

推荐答案

你可以通过设置 extentaspect 关键字从颜色数组中完成即时展示

You can do it from just the color array by setting extent and aspect keywords of imshow

import matplotlib as plt
import numpy as np

zval = np.random.rand(100, 100)
plt.imshow(zvals, extent=[0,3,-3,3], aspect="auto")
plt.show()

你得到的是 zval 数组刚刚压缩"在 [0:3, -3:3] 范围内.在 imshow 中仅绘制 zval 数组以使自己信服.

What you get is the zval array just "crunched in" the [0:3, -3:3] range. Plot just the zval array in imshow to convince yourself of this.

这篇关于具有来自单独 2D 数组的值的彩色 2D 网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆