pyplot散点图标记大小 [英] pyplot scatter plot marker size

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

问题描述

在散点图的pyplot文档中:

In the pyplot document for scatter plot:

matplotlib.pyplot.scatter(x, y, s=20, c='b', marker='o', cmap=None, norm=None,
                          vmin=None, vmax=None, alpha=None, linewidths=None,
                          faceted=True, verts=None, hold=None, **kwargs)

标记大小

s: 大小以磅为单位^ 2.它是标量或与x和y长度相同的数组.

s: size in points^2. It is a scalar or an array of the same length as x and y.

points^2是哪种单位?这是什么意思? s=10010 pixel x 10 pixel的意思吗?

What kind of unit is points^2? What does it mean? Does s=100 mean 10 pixel x 10 pixel?

基本上,我正在尝试制作具有不同标记大小的散点图,并且我想弄清楚s数字是什么意思.

Basically I'm trying to make scatter plots with different marker sizes, and I want to figure out what does the s number mean.

推荐答案

这种定义大小的方法可能有些混乱,但是您基本上是在指定标记的区域.这意味着,要使标记的宽度(或高度)加倍,您需要将s增大4倍.[因为A = W H =>(2W)(2H)= 4A ]

This can be a somewhat confusing way of defining the size but you are basically specifying the area of the marker. This means, to double the width (or height) of the marker you need to increase s by a factor of 4. [because A = WH => (2W)(2H)=4A]

但是,有一个原因,就是以这种方式定义了标记的大小.由于将面积缩放为宽度的平方,因此实际上加倍的宽度似乎会使大小增加2倍以上(实际上,将其增加4倍).要查看此内容,请考虑以下两个示例以及它们产生的输出.

There is a reason, however, that the size of markers is defined in this way. Because of the scaling of area as the square of width, doubling the width actually appears to increase the size by more than a factor 2 (in fact it increases it by a factor of 4). To see this consider the following two examples and the output they produce.

# doubling the width of markers
x = [0,2,4,6,8,10]
y = [0]*len(x)
s = [20*4**n for n in range(len(x))]
plt.scatter(x,y,s=s)
plt.show()

给予

注意大小如何快速增加.如果相反,我们有

Notice how the size increases very quickly. If instead we have

# doubling the area of markers
x = [0,2,4,6,8,10]
y = [0]*len(x)
s = [20*2**n for n in range(len(x))]
plt.scatter(x,y,s=s)
plt.show()

给予

现在,标记的表观大小以直观的方式大致呈线性增加.

Now the apparent size of the markers increases roughly linearly in an intuitive fashion.

关于点"的确切含义,出于绘制目的,它是任意的,您可以按常数缩放所有大小,直到看起来合理为止.

As for the exact meaning of what a 'point' is, it is fairly arbitrary for plotting purposes, you can just scale all of your sizes by a constant until they look reasonable.

希望这会有所帮助!

(回复@Emma的评论)

(In response to comment from @Emma)

我的措辞可能令人困惑.问题被问到是否将圆的宽度加倍,因此在第一张图片中,每个圆(当我们从左向右移动时)的宽度是前一个的两倍,因此对于面积而言,这是底数为4的指数.每个圆的面积 是最后一个圆的两倍,最后一个圆的底数为2.

It's probably confusing wording on my part. The question asked about doubling the width of a circle so in the first picture for each circle (as we move from left to right) it's width is double the previous one so for the area this is an exponential with base 4. Similarly the second example each circle has area double the last one which gives an exponential with base 2.

但是,在第二个示例(我们正在缩放区域)中,加倍的区域似乎使圆圈对眼睛大了两倍.因此,如果我们希望圆出现更大的n倍数,我们会将面积增加n而不是半径,因此外观尺寸会随面积线性缩放.

However it is the second example (where we are scaling area) that doubling area appears to make the circle twice as big to the eye. Thus if we want a circle to appear a factor of n bigger we would increase the area by a factor n not the radius so the apparent size scales linearly with the area.

编辑以显示@TomaszGandor的评论:

Edit to visualize the comment by @TomaszGandor:

这是标记大小的不同功能的外观:

This is what it looks like for different functions of the marker size:

x = [0,2,4,6,8,10,12,14,16,18]
s_exp = [20*2**n for n in range(len(x))]
s_square = [20*n**2 for n in range(len(x))]
s_linear = [20*n for n in range(len(x))]
plt.scatter(x,[1]*len(x),s=s_exp, label='$s=2^n$', lw=1)
plt.scatter(x,[0]*len(x),s=s_square, label='$s=n^2$')
plt.scatter(x,[-1]*len(x),s=s_linear, label='$s=n$')
plt.ylim(-1.5,1.5)
plt.legend(loc='center left', bbox_to_anchor=(1.1, 0.5), labelspacing=3)
plt.show()

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

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