Closed marcellastro closed 6 years ago
bbox_to_anchor
is a very tricky parameter in my experience. Changing only one of the coordinates does not necessarily move the labels up/down or left/right, but some combination. Have you tried smaller values to see if the legend is simply outside the figure?
Indeed,chainging the value of bbox_to_anchor solved it. Note though that I had to use 'bbox_to_anchor': (0.11,0.125). Which I have no intuition for...
Is there a better way to define the location of the legend?
I'll try to find an alternative to bbox_to_anchor
but I'm not aware of any at the moment. There are two other relevant parameters here: loc
specifies with respect to what point in the legend is bbox_to_anchor
referring, and bbox_transform
specifies with respect to which instance are the coordinates.
In the current implementation, the defaults are loc='upper right'
and bbox_transform=pylab.gcf().transFigure
(which means coordinates with respect to the figure, not any particular axis, see this tutorial. It seems that loc=center
requires more intuitive numbers (see the updated example), so I've updated it as the default for future releases. Please give it a try and let me know.
Although the provided example displays the legend as expected, my script does not.
Here is how I call the corner() function, in case you can spot an obvious mistake on my side:
figure = plottools.corner(X,colors=('black','blue','red'),\ labels=[r"${\rm log}{10}[M{\rm h}/M_\odot]$", r"${\rm r_s}$ [kpc]"],\ bins=[(100,100),(300,300),(300,300)], \ bins1d=[(10,10),(100,100),(100,100)], \ ticks=[(11.3,11.5,11.7,11.9,12.1),(10,20,30,40)],\ clevels=(0.68,0.95), ls2d=['-','--',':'],ls1d=['-','--',':',],\ medians1d=False,\ percentiles1d=False,\ style1d='curve',\ background='filled', \ bcolor=('yellow','orange'),alpha=0.25,\ names=['This Paper','Kenyon+14','McMillan+16'],\ verbose=False,limits=[(11.2,12.2),(1.0,40.5)],\ truths=bestfitparams,truth_color='black',smooth=[1.,1.],\ top_labels=False, names_kwargs = {'bbox_to_anchor': (0.75,0.95)},\ output=outputname)
I will email privately the entire script for clarity.