[英]How to use pcolor (or imshow) to plot color mapped squares centered on each X,Y scatter point
I have several thousand points with X,Y,C values (in numpy arrays).我有几千个 X,Y,C 值的点(在 numpy 数组中)。
I want each X,Y point to be plotted on a 2D image plot with a colored square around it (a box of size 40x40 units).我希望将每个 X、Y 点绘制在 2D 图像 plot 上,周围有一个彩色方块(一个 40x40 单位的盒子)。 Each X,Y point should be centered in the middle of the box.
每个 X、Y 点应位于框的中间。 The colour of the box will be mapped according to the C value.
框的颜色将根据 C 值映射。 The X,Y points are fairly randomly spaced.
X,Y 点的间距相当随机。 The points are arranged so that no boxes will overlap, they may touch, or have gaps.
这些点的排列方式是没有盒子会重叠,它们可能会接触或有间隙。
I'm not a Python expert so would appreciate if someone could help get me started on this with a few lines of code.我不是 Python 专家,所以如果有人可以帮助我用几行代码开始这方面的工作,我将不胜感激。 I believe that something like imshow or pcolor will be needed.
我相信需要像 imshow 或 pcolor 这样的东西。
Thanks,谢谢,
You can simply set up the size and marker type in the scatter
command.您可以简单地在
scatter
命令中设置大小和标记类型。
That'd be my solution:那将是我的解决方案:
X = 50 * np.round(10 * np.random.rand(100))
Y = 50 * np.round(10 * np.random.rand(100))
C = np.random.rand(100)
plt.figure(figsize=(12, 12))
sc = plt.scatter(X, Y, s=40**2, c=C, marker='s', cmap='gist_rainbow')
plt.scatter(X, Y, s=11**2, c='k')
plt.colorbar(sc)
plt.axis('equal')
plt.show()
The output would be the following: output 如下:
Hope that helps!希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.