2021年1月2日星期六

Python legend with GetDist tool : put a first block to the left and push a second block to the right

I would like to build 2 "blocks" mixing the color boxes and text with another which contains numerical values corresponding to the color box and text associated.

For the momment, I have this script which uses 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  )  

and I get the following legend on the upper right forming only one block :

Only one block

Now I would like to be able to have 2 blocks inside the same frame of the legend : from a first side on the left, I want the color boxes and text, and from another side, I would like to get the numerical values like "FoM =" 47.05 on the right, then forming 2 blocks separated by a chosen space chosen.

If I use 2 times the add_legend function instead of above (just one calling),

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

I get with this :

calling 2 times the add_lengend function

But as you can see, all the text part is not displayed, just color boxes and numerical values.

How to make 2 blocks separated by a chosen space and inside a single frame, one block on the left which contains the color boxes and text, and a second one pushed on the right and which contains the part of all the "FoM = ...." aligned with the first block ?

Any suggestion/clue is welcome.

https://stackoverflow.com/questions/65545743/python-legend-with-getdist-tool-put-a-first-block-to-the-left-and-push-a-secon January 03, 2021 at 09:08AM

没有评论:

发表评论