简体   繁体   English

如何使用 pcolor(或 imshow)到 plot 以每个 X、Y 散点为中心的颜色映射正方形

[英]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.

相关问题 如何在matplotlib中为散点图中的每个点绘制不同深浅的颜色? - How to plot different shades of a color for each point in a scatter plot in matplotlib? 如何使用为每个点单独指定的颜色创建散点图? - How to create a scatter plot with color specified for each point individually? 指定散点图中每个点的颜色(matplotlib) - Specify color of each point in scatter plot (matplotlib) 如何使用Matplotlib pyplot pcolor为绘图中的每个网格提供不同的颜色 - How do I use Matplotlib pyplot pcolor to provide distinct color to each grid in my plot 如何分别为散点图着色? - How to color the point of a scatter plot separately? 如何 plot 散点图 plot 这也表示 x 的每个值的 y 值的直方图 - How to plot a scatter plot which would also represent the histogram for y value for each value for x Matplotlib散点图,每个x点有2个y点 - Matplotlib scatter plot with 2 y-points per x-point 有没有办法获得散点图中单个点的 x 和 y 坐标? - Is there a way to get the x and y coordinate of a single point in a scatter plot? Python散点图多个具有相同颜色的x点和y点 - Python Scatter Plot Multiple x points and y points with same color 如何在同一图表上使用 matplotlib 到 plot 2 组 (x,y) 值作为散点 plot(由线连接)? - How to use matplotlib to plot 2 sets of (x,y) values on the same graph as a scatter plot (connected by lines)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM