0

I have a subplot with an external, horizontal legend (figure legend), and super title (suptitle). I would like to align them on the bottom of the text, vertically. I set the vertical position of the title with fig.suptitle('title', ha='left', y=placement). When I try to set the legend's location with fig.legend(handles, labels, loc=(0.65, placement)), It is not aligned. I suspect this is an issue with the point the objects are aligned on and that the legend has a border... so I changed the padding of the legend to 0, but still have to tweak it.

How could I explicitly set the anchor point, or node, of the suptitle and legend?

EDIT

Image attached below. I believe I have solved the problem with setting the suptitle parameter va='bottom, and legend parameters borderpad=0.0, borderaxespad=0. Now, if I do have a border, how would I do this? I would also like to know how to explicitly set the anchor point of the legend.

SOLUTION

When you set the bbox_to_anchor parameter in the legend, it basically changed where the legend is clipped to. If the bbox has no height or width (2-tuple), it is a point. The loc parameter is then the point on the legend frame that is anchored to the bbox. When loc is used on it's on, the bbox is determined by MPL.

Let's say I wanted the title on the left, legend on the right (with no box), and horizontally aligned at the bottom. Mmy solution would look like:

fig.suptitle('title', ha='left', va='bottom', y=placement, x=0.02)
fig.legend(handles, labels, 
    loc='lower right',
    bbox_to_anchor=(0.98, placement), 
    borderpad=0.0,
    borderaxespad=0,
    ncol=3,
)

enter image description here

likethevegetable
  • 264
  • 1
  • 4
  • 17
  • Could you please add an image of how the plot currently looks like and how you want it to look? Also, please check [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Francisca Concha-Ramírez Dec 04 '19 at 16:25
  • You will definitely need to use `verticalalignment="bottom"` for the suptitle. Also, how did you change the padding? Using `borderpad=0, borderaxespad=0` it should be perfectly aligned (but will of course look awful). – ImportanceOfBeingErnest Dec 04 '19 at 16:30
  • Thanks for the quick replies. I thought `va=baseline` would work at first.. but tried `va='bottom` on your suggestion and it has improved-I think it is perfectly aligned now. Please note that I have no border on the legend. If I did however, this presents another problem. I'm assuming vertical/horizontal alginment changes the anchor? – likethevegetable Dec 04 '19 at 16:51
  • @FranciscaConcha-Ramírez please see the updated question. – likethevegetable Dec 04 '19 at 17:44
  • Check [this question](https://stackoverflow.com/questions/39803385/what-does-a-4-element-tuple-argument-for-bbox-to-anchor-mean-in-matplotlib) – ImportanceOfBeingErnest Dec 04 '19 at 23:14
  • Thank you very much, exactly what I was looking for. – likethevegetable Dec 05 '19 at 13:52

0 Answers0