使用GetDist工具的Python图例:将第一个块放在左侧,将第二个块推到右侧

2024-06-01 01:49:28 发布

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

我想建立2个“块”混合的颜色框和文本与另一个包含相应的颜色框和文本相关的数值

目前,我有一个使用getdist library的脚本:

g = plots.get_subplot_plotter()
g.add_legend(['Opt. Flat. No Gamma. - WL - FoM = 47.05',
'Opt. Flat. No Gamma. - GCsp - FoM = 52.12',
'Opt. Flat. No Gamma. - GCph - FoM = 61.88',
'Opt. Flat. No Gamma. - GCsp + GCph+WL+XC - FoM = 1209.80',
'Opt. Flat. No Gamma. - Common bias - FoM = 1567.18'],
legend_loc='upper right',
bbox_to_anchor=(bottom_right_plot, top_left_plot),
bbox_transform=plt.gcf().transFigure, # this is the x and y coords we extracted above
borderaxespad = 0, # this means there is no padding around the legend
)

我在右上角看到以下图例,仅形成一个块:

Only one block

现在,我希望在图例的同一帧中有两个块:从左侧的第一面开始,我希望看到颜色框和文本,从另一侧开始,我希望得到右侧的数值,如"FoM =" 47.05,然后形成两个块,由选定的空间分隔

如果我使用2次add_legend函数而不是上面的函数(仅一次调用)

# First legend
g.add_legend(['Opt. Flat. No Gamma. - WL :',
'Opt. Flat. No Gamma. - GCsp :',
'Opt. Flat. No Gamma. - GCph :',
'Opt. Flat. No Gamma. - GCsp +(GCph+WL+XC) :',
'Opt. Flat. No Gamma. - Common bias :'],
legend_loc='upper right',
bbox_to_anchor=(bottom_right_plot, top_left_plot),
bbox_transform=plt.gcf().transFigure, # this is the x and y coords we extracted above
borderaxespad = 0, # this means there is no padding around the legend
)

# Second legend
g.add_legend([
' FoM = 47.05',
' FoM = 52.12',
'FoM = 61.88',
'FoM = 1209.80',
'FoM = 1567.18'],
legend_loc='upper right',
bbox_to_anchor=(bottom_right_plot, top_left_plot),
bbox_transform=plt.gcf().transFigure, # this is the x and y coords we extracted above
borderaxespad = 0, # this means there is no padding around the legend
)

我明白这一点:

calling 2 times the add_lengend function

但正如您所看到的,所有文本部分都不会显示,只显示颜色框和数值

如何在一个框架内用选定的空间分隔两个块,一个在左侧,包含颜色框和文本,另一个在右侧,包含与第一个块对齐的所有“FoM=…”部分


Tags: theno文本rightaddplotis颜色