具有来自单独 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:
不幸的是,这只是显示了色差,而不是我想可视化的2D区域.
Unfortunately this simply displays the colorarr, and not the 2D region I would like to visualize.
谢谢!
你可以通过设置 的
extent
和 aspect
关键字从颜色数组中完成即时展示
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.