-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Legend Title Left Alignment #12388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I agree that it would make sense for |
Actually, Also, |
Oops. Maybe remove good first issue. I thought it strange that modifying the legend box got the desired effect. |
This would actually need more substantial changes in the layouting of the legend. Not sure we have enough layout control mechanisms in place to do this. |
Instead of building up a rather complex API here I would be very much in favour of making the vpackers and hpackers in legend public, such that users may easily manipulate them the way they like. They do that anyways, (in this case probably due to my bad influence) but then with a clear concience 😉. |
@ImportanceOfBeingErnest, Absolutely it was your bad influence! Haha! Just wondering: Couldn't the "x" of the title be moved to the same x as the handles, or a fixed distance from the left edge of the legend? |
@Marriaga Unfortunately its not that easy. The two objects in the VPacker don't really know anything about each other's widths the way its written now, so they can either be centre aligned or left/right aligned. Both have issues though depending on the relative size of the legend title and the legend entries. I'm -0.5 on making the packers public. That API is pretty mysterious, and you might as well just tell people to use private methods if you tell people to directly manipulate these objects. Making them public makes it impossible for us to change this code in the future. I guess I'm actually not really sure that just changing the align of import numpy as np
import matplotlib.pyplot as plt
fig, axs = plt.subplots(1, 2, figsize=(5,3))
for i in range(2):
ax = axs[i]
ax.plot(range(10), label='Boo')
ax.plot(range(10), label='Who')
leg = ax.legend(loc='center left')
if i==1:
leg.set_title('Long Legend Title')
else:
leg.set_title('Short')
leg._legend_box.align='left'
plt.show() |
I'm also -0.5 on making the Packers public. The API seems not mature enough to be released. A possible workaround to support title positioning could be to support a list of values for VPacker(align=...). So that we could add
|
Side remark:Actually, the current choice for While it looks good with short titles (top left), long titles result in awkwardly centered entires (top right). OTOH, with Would we be willing to change that to
|
a) I think it'd be fine to add a kwarg, but maybe just add it to |
Because someone just asked on gitter about the legend text alignment, I'm mentionning it here, as it seems related and equally not easily adjustable. A workaround could be
So this could be taken into account for whatever action is taken here for the title. |
Whatever you implement, you should also consider what it looks like if someone passes 'right'. Here's what happens when varying _legend_box.align:
If somebody really wants to get into this, it might be sweet if one was able to align the whole legend right, with the labels on the right. That sometimes looks better when the legend is at the right of a plot. |
Hi, would be great to have this feature, I just stumbled over this issue here, but the title alignment has bothered me for years now. I can put a PR together to move this forward, if no one else is working on it. |
@HDembinski that'd be great! |
I'm trying to align my legend title on the left of the legend box. I assumed this would work:
However only this worked:
Seems like something is not working as expected, especially since I'm accessing something hidden.
The text was updated successfully, but these errors were encountered: