简体   繁体   English

为散点图找到正确的标记大小

[英]Finding the right marker size for a scatter plot

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()

that is I square the sigsize and the dpi (use 15 and 80 respectively), and divide by the dimensionality of the grid. 即我将sigsize和dpi平方(分别使用15和80),然后除以网格的维数。 Finally I divide this by 3 as I found this to work. 最终,我发现将其除以3即可。

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. 我想要的是一个网格,其中每个正方形都使用尽可能多的空间,但在其他节点的空间上没有“侵权”,因此标记重叠。

As far as I can read the figsize is given in inches. 据我所知,figsize以英寸为单位。 dpi is - dots per inch, and the markersize is specified in - points. dpi是-每英寸点数,并且标记大小在-点中指定。 If the points is the same as dots, you would then have dpi figsize amount of dots on each axis. 如果这些点与点相同,则每个轴上将具有dpi图大小的点数。 The xdim ydim is the amount of nodes in my grid. xdim ydim是网格中节点的数量。 Dividing the pow(dpi figsize, 2) / xdim ydim should then give the amounts of dots per node, and the right size for each marker I thought. 然后除以pow(dpi figsize,2)/ xdim ydim应该给出每个节点的点数,以及我认为的每个标记的正确大小。 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. 我减了3分,这实际上可以满足我通常所用尺码的要求,但并不是全部。 (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. 您也可以使用矩形而不是圆形。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM