将xy对的坐标从“数据”转换为“轴分数”

2024-06-26 17:44:09 发布

您现在位置:Python中文网/ 问答频道 /正文

A.背景

我正在用Python matplotlib绘制叶绿素图。
ax.textax.annotate函数有一些错误,我在这里发布帮助。你知道吗

B.我的问题

A.当我使用下面的代码在地图上添加一些字符串时:

ax.annotate("LOL",xy=(114.5,38.5), xycoords = 'data',fontsize = 15, 
                 fontstyle = 'italic',zorder =3) `

无论我如何更改xypairs,字符串“LOL”总是位于左下角的位置。如图所示:

http://i4.tietuku.com/620a3bb6052d7859.png

B.更改xycoords类型:

ax.annotate("LOL",xy=(0.4,0.6),xycoords='axes fraction',    
             fontsize = 15, fontstyle = 'italic',zorder =3,color = 'w')   

如图所示:

http://i11.tietuku.com/f1e175b427377160.png

C.我的分析

我想可能是投影设置的问题。为了添加地图比例,我选择tmerc投影:

map = Basemap(projection='tmerc', lon_0 =xxx, lat_0 = xxx,
             ellps = 'WGS84', llcrnrlon=xxx,llcrnrlat=xxx,urcrnrlon=xxx,
             urcrnrlat=xxx,lat_ts=0,resolution='i',suppress_ticks=True)

当我使用map = basemap(llcrnrlon=xxx ,llcrnrlat=xxx, urcrnrlon=xxx, urcrnrlat=xxx)时,xycoords = 'data'类型工作得很好。你知道吗

但是我的字符是基于数据点(表示每个多边形的区域名称)的,data类型是我需要选择的。因此,我想学习一些函数,可以将data类型中的xypairs更改为axes fraction类型。然后,问题就可以解决了!你知道吗


Tags: 函数字符串类型data地图axxxxxy