pyplot散点图标记大小

article/2025/10/12 5:07:03

本文翻译自:pyplot scatter plot marker size

In the pyplot document for scatter plot: 在散点图的pyplot文档中:

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)

The marker size 标记大小

s: size in points^2. s:以磅为单位的大小^ 2。 It is a scalar or an array of the same length as x and y. 它是标量或与x和y长度相同的数组。

What kind of unit is points^2 ? points^2是什么样的单位? What does it mean? 这是什么意思? Does s=100 mean 10 pixel x 10 pixel ? s=100表示10 pixel x 10 pixel吗?

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含义是什么。


#1楼

参考:https://stackoom.com/question/10DLe/pyplot散点图标记大小


#2楼

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 = W H => (2W) (2H)=4A] 这意味着,要使标记的宽度(或高度)加倍,您需要将s增加4倍。[因为A = W H =>(2W) (2H)= 4A]

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). 由于将面积缩放为宽度的平方,所以实际上加倍宽度似乎会使大小增加2倍以上(实际上,将其增加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()

gives

在此处输入图片说明

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

gives

在此处输入图片说明

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. 至于“点”的确切含义,出于绘图目的,它是任意的,您可以按常数缩放所有大小,直到看起来合理为止。

Hope this helps! 希望这可以帮助!

Edit: (In response to comment from @Emma) 编辑:(以回应@Emma的评论)

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. 问题被问到是否将圆的宽度加倍,因此在每个圆的第一张图片中(当我们从左向右移动时)它的宽度是前一个圆的两倍,因此对于面积而言,这是底数为4的指数。每个圆的面积是最后一个圆的两倍,最后一个圆的底数为2。

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. 因此,如果我们想让一个圆出现一个较大的n倍,我们将使面积增加n倍而不是半径,因此外观尺寸会随该面积线性变化。


#3楼

If the size of the circles corresponds to the square of the parameter in s=parameter , then assign a square root to each element you append to your size array, like this: s=[1, 1.414, 1.73, 2.0, 2.24] such that when it takes these values and returns them, their relative size increase will be the square root of the squared progression, which returns a linear progression. 如果圆的大小对应于s=parameter的平方,则将平方根分配给附加到大小数组的每个元素,如下所示: s=[1, 1.414, 1.73, 2.0, 2.24]这样当它们取这些值并返回它们时,它们的相对大小增加将是平方级数的平方根,并返回线性级数。

If I were to square each one as it gets output to the plot: output=[1, 2, 3, 4, 5] . 如果我将每个平方取平方,则将其输出到绘图中: output=[1, 2, 3, 4, 5] Try list interpretation: s=[numpy.sqrt(i) for i in s] 尝试列表解释: s=[numpy.sqrt(i) for i in s]


#4楼

It is the area of the marker. 它是标记的区域 I mean if you have s1 = 1000 and then s2 = 4000 , the relation between the radius of each circle is: r_s2 = 2 * r_s1 . 我的意思是,如果您有s1 = 1000 ,然后s2 = 4000 ,则每个圆的半径之间的关系为: r_s2 = 2 * r_s1 See the following plot: 请参见下图:

plt.scatter(2, 1, s=4000, c='r')
plt.scatter(2, 1, s=1000 ,c='b')
plt.scatter(2, 1, s=10, c='g')

在此处输入图片说明

I had the same doubt when I saw the post, so I did this example then I used a ruler on the screen to measure the radii. 看到帖子时,我也有同样的疑问,所以我做了这个例子,然后在屏幕上用尺子测量半径。


#5楼

You can use markersize to specify the size of the circle in plot method 您可以在plot方法中使用markersize指定圆的大小

import numpy as np
import matplotlib.pyplot as pltx1 = np.random.randn(20)
x2 = np.random.randn(20)
plt.figure(1)
# you can specify the marker size two ways directly:
plt.plot(x1, 'bo', markersize=20)  # blue circle with size 10 
plt.plot(x2, 'ro', ms=10,)  # ms is just an alias for markersize
plt.show()

From here 从这里

在此处输入图片说明


#6楼

I also attempted to use 'scatter' initially for this purpose. 我也尝试为此目的最初使用“分散”。 After quite a bit of wasted time - I settled on the following solution. 在浪费大量时间后-我决定采用以下解决方案。

import matplotlib.pyplot as plt
input_list = [{'x':100,'y':200,'radius':50, 'color':(0.1,0.2,0.3)}]    
output_list = []   
for point in input_list:output_list.append(plt.Circle((point['x'], point['y']), point['radius'], color=point['color'], fill=False))
ax = plt.gca(aspect='equal')
ax.cla()
ax.set_xlim((0, 1000))
ax.set_ylim((0, 1000))
for circle in output_list:    ax.add_artist(circle)

在此处输入图片说明

This is based on an answer to this question 这是基于对这个问题的答案


http://chatgpt.dhexx.cn/article/uFKJgvYi.shtml

相关文章

matplotlib:marker类型/size/空心

marker类型 plt.plot(RSEP_data, colorcolor[1], labelRSEP, linestyle--, markerv, markerfacecolornone, markersize10)

python pyplot 宽高等比_如何使pyplot分散中的markersize不依赖于图形的比例?

我在做一个模拟,我想用pyplot来显示。在模拟中,有一些圆在移动,当它们重叠时会发生一些事情。当我尝试用pyplot显示这个时,标记的大小不正确。在 我试过改变标记的大小,但没有解决问题。经过一些测试,我意识…

详解Axes()中的markersize

在Matplotlib中,Axes对象的markersize参数是指绘制图形中marker(如散点图中的点)大小的参数。这个参数指定marker的直径的长度,单位为像素或点(pt)。具体来说,它控制marker在x轴和y轴方向上的大…

Matlab scatter/plot绘制图时,单点的'MarkerSize'与空间位置的关系

scatter scatter(axes, x, y, sz, ‘Marker’, ‘o’); scatter()函数中参数sz决定’Marker’(即’o’)的标记面积(大小),默认单位是平方磅(points),o’在坐标轴中的宽度…

markersize

为什么80%的码农都做不了架构师?>>> plot([1,2,3,4],[2,5,6,9],c-pentagram,markersize,35) %pentagram:是五角星,c代表颜色亮蓝;-代表线性实线,markersize(即五角星的大小)为35 下面是画图的颜色和线型,matlab 中画图的颜色 字母 颜色…

plot中的 markersize

‘markersize’ plot([0,1,2,3,4],[0,2,5,6,9],‘c-pentagram’,‘markersize’,15) 画图的命令是: marker是图上画上点的地方表上符号,不如点,方框,圆框,十字,星号,等等 后面的size就是其大小…

matlab2015的marker,matlab中markersize什么意思

matlab中如何调整plot多变量绘图中的markersize MATLAB中的绘图语言 plot(j,len1-i,ro,MarkerS...参数那么多,有点晕啊,每个参数代表什么意思啊??? 前面的j和len1-iplot(...,PropertyName,PropertyValue,...) plot(j,l…

matlab中marker太密,markersize_想问下MATLAB里 ‘Markersize’ 设置的值是‘Marker_

广告位API接口通信错误,查看德得广告获取帮助 想问下MATLAB里 ‘Markersize’ 设置的值是‘Marker_size’是什么意思 就是标准尺寸。 ‘markersize’plot([0,1,2,3,4],[0,2,5,6,9],c-pentagram,markersize,15) 画图的命令是:marker是图上画上点的地方表上符号,不如点,方框,…

matlab里markersize,Matlab scatter/plot绘制图时,单点的'MarkerSize'与空间位置的

Matlab scatter/plot绘制图时,单点的MarkerSize与空间位置的 Matlab scatter/plot绘制图时,单点的MarkerSize与空间位置的关系 scatter scatter(axes, x, y, sz, ‘Marker’, ‘o’); scatter()函数中参数sz决定’Marker’(即’o’)的标记面积(大小),默认单位是平方磅(poin…

[MATLAB学习笔记] MATLAB里 ‘Markersize’ 设置的值是‘Marker_size’

Markersize意思是标记尺寸,那么 Marker_size 的值代表的就是标记尺寸的大小。 例如在 plot 作图中,事先定义两个数据 x-pi:0.5:pi , ysin(x) ,运行作图命令 plot(x,y,o,Markersize,12) o 的意思为坐标点用圆圈标记,那么 Markersize 的意思…

Spring Authorization Server的使用

Spring Authorization Server的使用 一、背景二、前置知识三、需求四、核心代码编写1、引入授权服务器依赖2、创建授权服务器用户3、创建授权服务器和客户端 五、测试1、授权码流程1、获取授权码2、根据授权码获取token3、流程演示 2、根据刷新令牌获取token3、客户端模式4、撤…

SpringSecurityOAuth已停更,来看一看进化版本Spring Authorization Server

Spring Authorization Server是Spring Security OAuth的进化版本,Spring Security OAuth官方已经宣布“End of Life”了。Spring Security OAuth使用的是OAuth2.0标准而Spring Authorization Serve引入了对OAuth 2.1和OpenID Connect 1.0规范的支持,并提…

Spring Authorization Server1.0 介绍与使用

一、版本使用 1、Java&#xff1a;17或者更高的版本。 2、springboot 3.0 3、Spring Authorization Server 1.0版本。 <dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-oauth2-authorization-server</ar…

curl php authorization,PHP CURL 执行 Authorization 请求

PHP CURL 扩展可以帮助我们快速实现HTTP请求。查看更多: 博客原文 在使用豆瓣OAuth登录接口时&#xff0c;我们需要发送这样的HTTP REQUEST 请求:GET /v2/user/~me HTTP/1.1 Host: https://api.douban.comAuthorization: Bearer a14afef0f66fcffce3e0fcd2e34f6ff4 在命令行中我…

spring authorization server使用说明

spring authorization server使用说明 相关依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency><!-- 授权客户端 --><dependency><groupId…

Spring Authorization Server 系列(二)获取授权码

Spring Authorization Server 系列&#xff08;二&#xff09;获取授权码 概述获取授权码获取授权码的url逻辑解析匹配url参数解析 概述 Spring Authorization Server 是基于 OAuth2.1 和 OIDC 1.0 的。 只有 授权码&#xff0c;刷新token&#xff0c;客户端模式。 获取授权码…

Spring Authorization Server 0.2.3变化

目录 引言联邦认证示例public client默认设置Introspection端点自定义访问令牌类型⭐️令牌生成器优化⭐️拆分Client认证逻辑OAuth2ClientAuthenticationProvider⭐️授权端点逻辑⭐️关于0.3.0版本中JwtEncoder相关变化⭐️ 引言 Spring社区在2022-03-24 19:56发布了Spring …

spring authorization server 0.3.1 - 默认示例

spring authorization server 0.3.1 - 默认oidc 开始1、default-authorizationserver项目1.1、AuthorizationServerConfig.java1.2、DefaultSecurityConfig.java1.3、Jwks.java1.4、KeyGeneratorUtils.java1.5、DefaultAuthorizationServer.java1.6、application.yml 2、client…

Authorization Server 认证服务

Hi Auth HiAuth是一个开源的基于Oauth2协议的认证、授权系统&#xff0c;除了标准的Oauth2授权流程功能外&#xff0c;还提供了应用管理、用户管理、权限管理等相关功能。 在这个项目中你能够了解到如何基于spring-security-oauth2-authorization-server实现自己的Authorizat…

java authorization_OkHttp3 之 Authorization处理认证(四)

处理验证 这部分和HTTP AUTH有关. HTTP AUTH 使用HTTP AUTH需要在server端配置http auth信息, 其过程如下:客户端发送http请求 服务器发现配置了http auth, 于是检查request里面有没有”Authorization”的http header 如果有, 则判断Authorization里面的内容是否在用户列表里面…