-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Continued Text Alignment Issues #1742
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
It looks like the offset for the AnchoredOffsetbox (which AnchoredText is subclassed from) is only applied to the patch object, never the text object. Furthermore, the Anchor's offset is calculated only when the frame is made to be visible. I vaguely remember this codepath being tinkered with fairly recently with respect to legend placement. Maybe we borked something then? The relevant codepath looks to be the same for both master and v1.2.x branches, so I would say that this might be a regression for v1.2.x. |
Although it is not clearly documented, Changing the alignments of the text inside the AnchoredText (or anything derived from TextArea) is not supported. We may need some warning here though. If you want to adjust the position of the AnchoredText, you need to fiddle with parameters like loc, bbox_to_anchor, or bbox_transform. While there is subtle difference, the legend location section of the legend guide (http://matplotlib.org/users/legend_guide.html) may be useful. |
@leejjoon: Since I've never used the AnchoredText stuff, can you clarify what isn't supported? In the example, it looks like the horizontalalignment of the text is set on creation of the AnchoredText object, not changed later. If it's possible to add a warning in this case, I think that would be great. (There are actually lots of places around matplotlib where things can't be changed after creation time where warnings might be helpful -- or to just fix it so it works where possible or easy to do.) |
Can horizontal alignment be supported here? Is this something that can eventually be added? Or is it extremely complicated? The reason why I think this is important is that AnchoredText is extremely powerful for including captions/titles inside a figure vs. using ax.set_title(). (This is how I use AnchoredText a majority of the time.) It's much easier than trying to figure out the correct placements when using basemap (which can alter the shape of the viewing window). It doesn't really matter when the title is a single line, but when you move to multiple lines, being able to center is useful. |
@mdboom, the placement of AnchoredText is similar to the legend, i.e., the position of the text is determined by the loc parameter and the bounding box that it is anchored to. And such placement conflicts with setting the alignments of the text (ha & va). Implementation-wise, the placement of AnchoredText is done using left and baseline alignment. I will try to add a warning message. @pmarshwx, Now I see your problem, you meant alignments of multiple lines. I must confess that the multiline support of the current AnchoredText implementation is not good enough. This is something that need to be improved I guess. Meanwhile, here is a workaround, although more complicated. import matplotlib.pyplot as plt
from matplotlib.offsetbox import TextArea, VPacker, AnchoredOffsetbox
fig = plt.figure()
ax0 = fig.add_subplot(111)
prop=dict(size=24)
t1 = TextArea("Test Test", textprops=prop)
t2 = TextArea("Test", textprops=prop, minimumdescent=False)
offsetbox = VPacker(children=[t1, t2], align="center", pad=0, sep=4)
at = AnchoredOffsetbox(loc=9, child=offsetbox, bbox_to_anchor=ax0.bbox)
ax0.add_artist(at)
at.patch.set_boxstyle("round, pad=0, rounding_size=0.25")
plt.show() |
@leejjoon: So I think for 1.3.x, all we'll want to do with this is add a warning message when AnchoredText is mixed with ha and va. Is that correct? We can try to fix some of the deeper issues later. |
@leejjoon: Do you agree with my suggestion above? |
Yes, that sounds reasonable. |
Was this warning message ever merged? |
@dmcdougall: No. |
See #2166. |
#2166 was merged so I'm closing this. |
When using AnchoredText, setting the horizontal alignment to 'center' causes the text to be centered around the left-most edge of the text space. In other words, the text is being centered around the location of the the left spine of the text box plus the padding amount.
If you try to right-align the text, the entire text is actually found to the left of the text box.
Here's a simple example and figure to illustrate. Note, this works with or without ImageGrid.
Here are a couple of issues and pull requests that could be related.
Issue #1571
Pull Request #1081
Pull Request #1589
The text was updated successfully, but these errors were encountered: