首页 > 编程知识 正文

python散点图点的大小,python散点图标记每一个点

时间:2023-05-06 00:10:48 阅读:9203 作者:843

I ' mgettingquitedesperateaboutthis,icouldn ' tfindanythingonthewwsofar。

Here's the situation:

I am working with Python。

Ihave3arrays : the x-coordinates,the y-coordinates and the radius。

iwanttocreateascatterplotwiththegivenx-Andy-coordinates。

So far,everythingworkshowiwantitto.hereiswhat ' sbotheringme :

thecirclesizeofeachpointinthescatterplotshouldbedefinedbytheradiusarray。

thethevaluesofthecoordinatesandtheradiusareinsameunits.more explicitly : let ' sassumeihaveapointat (1, 1 ) with radius 0.5 assigned.theniwanttogetacircleintheplotcenteredat (1,1 ) andwiththebordergoingthroughtthepoints (1.5,1 )

watiamstrugglingwithistofindouttheratioofplotpointstothelengthinanaxis.ineedtoworkwithpointsbecauseasfarasicansee, thecirclesizeofthescatterplotisgiveninpointvalues.soif let ' ssaymyaxisgoesfrom0to 10,ineedtoknowhowmanypointststhereareareareinbetwetwetwetwetwbetwetwetwettttwer

Can anybody help me? Or is there another way of doing this?

高级thanks in。

解决方案

I ' mjumpinginfromyourotherstackoverflowquestion.ithinktheapproachyoupresentedasanswertothepresentquestionwon ' tworkexaction

First,the size of the markers is in points,not in pixels. In typography,thepointisthesmallestunitofmeasureandcorrespondinmatplotol

Second,thesizeofthemarkersinplt.scatterarerelatedtothediameterofthecircles,not the radius。

sothesizeinpointsofeachmarkershouldbecalculatedas :

size _ in _ points=(2* radius _ in _ pixels/fig _ dpi * 72 points/inch ) **2

移动器,as shown in the MWE below,itispossibletocalculatethesizeofthemarkerradiusinpixelsdirectlywithmatplotlibtransformations

import numpy as np

import matplotlib.pyplot as plt

PLT.close(all ) )。

# Generate some data :

N=25

x=NP.random.rand(n ) 0.5

y=NP.random.rand(n ) 0.5

r=NP.random.rand(n )/10

#打印the data :

fig=PLT.figure (face color=' white ',fig size=(7,7 ) )

scat=ax.Scatter(x,y,s=0,alpha=0.5,clip_on=False ) ) ) ) ) ) )。

# Draw figure :

fig.canvas.draw (

# Calculate radius in pixels :

RR_pix=(ax.transdata.transform ) NP.v堆叠([ r,r] ).t ) -

rpix,_=rr_pix.T

# calculateandupdatesizeinpoints :

size_pt=(2*rpix/fig.dpi*72 ) *2

sat.set_sizes(size_pt ) )。

#保存并显示图形:

fig.save fig (scatter _ size _ axes.png ) )

plt.show () )

apoint at (1,1 ) with radius 0.5 assignedwillresultinacircleintheplotcenteredat ) 1,1 ) andwiththebordergoingthepointhe

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。