为散点图找到正确的标记大小 [英] Finding the right marker size for a scatter plot

查看:45
本文介绍了为散点图找到正确的标记大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制一个网格,其中网格中的每个节点都由一个点绘制,并带有特定的颜色代码(取自该节点中存储的向量).

I want to plot a grid where each node in the grid is drawn by a dot, with a certain color code (taken from a vector stored in the node).

这里的网格大小取决于我正在运行的仿真的大小.我还没有弄清楚画布大小和标记大小之间的关系.现在,我使用以下公式:

the grid here varies in size depending on the size of the simulations I am running. I have yet to figure out the relationship between the canvas size and the marker size. Now I use the following formula:

markersize = (figsize*figsize*dpi*dpi)/(xdim*ydim)
plt.scatter(X, Y, s=markersize/3, marker='s', c=Z, cmap=cm.rainbow)
plt.show()

即我将sigsize和dpi平方(分别使用15和80),然后除以网格的维数.最终,当我发现它可以工作时,我将其除以3.

that is I square the sigsize and the dpi (use 15 and 80 respectively), and divide by the dimensionality of the grid. Finally I divide this by 3 as I found this to work.

但是我还无法弄清楚如何分析得出正确的标记大小.我想要的是一个网格,其中每个正方形都使用尽可能多的空间,但在其他节点的空间上没有侵权",因此标记重叠.

But I haven't been able to work out how to analytically get the right marker size. What I want is a grid where each square uses as much a space as it can but without "infringinig" on the other nodes' space, so that the markers overlap.

据我所知,figsize以英寸为单位.dpi是-每英寸点数,并且标记大小在-点中指定.如果这些点与点相同,则每个轴上将有dpi figsize个点.xdim ydim是网格中节点的数量.然后除以pow(dpi figsize,2)/xdim ydim应该给出每个节点的点数,以及我认为的每个标记的正确大小.但这使标记过大.我减了3分,这实际上可以满足我通常所用尺码的要求,但并不能满足所有要求.(我猜一个点和一个点不一样,但是关系是什么?)

As far as I can read the figsize is given in inches. dpi is - dots per inch, and the markersize is specified in - points. If the points is the same as dots, you would then have dpifigsize amount of dots on each axis. The xdimydim is the amount of nodes in my grid. Dividing the pow(dpifigsize, 2) / xdimydim should then give the amounts of dots per node, and the right size for each marker I thought. But that made the markers too big. I diveded by 3 and it sort of worked practically for the sizes I usually run, but not for all. (I am guessing a point and a dot is not the same, but what is the relation?)

我该如何为此找到正确的答案?理想情况下,我想要一张非常细腻的图片,可以在某些区域放大以更好地查看颜色细微差别.

How do I work out the correct answer for this? Ideally I would like a very granular picture where I could zoom in an certain areas to get a finer look at the color nuances.

推荐答案

如果要精确控制标记大小并使其与图形成比例,则可以使用

If you want to control the marker size precisely and have it scale with the figure, you can use a patch instead of a regular marker. Here's an example:

from matplotlib import pyplot as plt
from matplotlib.patches import Circle

x = [1, 2, 3, 4, 5]
y = [1, 3, 1, 2, 4]
colors = [10, 215, 30, 100]

cmap = plt.cm.jet
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')

for (x, y, c) in zip(x, y, colors):
    ax.add_artist(Circle(xy=(x, y), radius=0.5, color=cmap(c)))      

ax.set_xlim(0, 6)
ax.set_ylim(0, 6)
plt.show()

您也可以使用矩形而不是圆形.

You could also use a rectangle instead of a circle.

这篇关于为散点图找到正确的标记大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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