seaborn.objects: Text isn't shown properly when too close the axis border #3170
Replies: 7 comments
-
Which text are you talking about here? And what is the expected behavior? |
Beta Was this translation helpful? Give feedback.
-
Also please put the example code in the issue as text (i.e. something that can be copy-pasted) rather than a screenshot. |
Beta Was this translation helpful? Give feedback.
-
gd = pd.DataFrame({
"price": [10000, 0],
"name": ["A", "B"]
})
(
so.Plot(data=gd, x="price", y="name", text="price")
.add(so.Bar())
.add(so.Text())
) The text that was added by |
Beta Was this translation helpful? Give feedback.
-
I'm still interested in what precisely you think the expected behavior is, because two possible things could happen so that the text is not located "outside of the figure":
Neither is exactly simple. (1) is controlled by matplotlib; I don't think seaborn can work around it, and there are some technical reasons why matplotlib's behavior is understandable (or, at least, avoids some significant complexity; matplotlib/matplotlib#10497). (2) makes sense when text is just slightly running over the axes, but it leads to very surprising behavior in other cases (matplotlib/matplotlib#14354). You can activate the solution for (2) yourself:
I'm open to this being the default behavior (it is for |
Beta Was this translation helpful? Give feedback.
-
I think the default value for I would maybe also consider setting default as |
Beta Was this translation helpful? Give feedback.
-
Well, here's a counterexample: x = list("ABCEDFG")
y = [i * 100 for i in range(1, 8)]
(
so.Plot(x, y, text=y)
.add(so.Bar())
.add(so.Text(halign="left"))
) It's possible that halign/valign defaults could depend on the layer orientation, but that's fairly magical. (Also personally I prefer bar labels to be inside the bar, right- or top-aligned to the edge). |
Beta Was this translation helpful? Give feedback.
-
Thanks for the counter-example. In such a case, I agree it doesn't make sense to change this default (for halign). |
Beta Was this translation helpful? Give feedback.
-
Example:
Similar issues occur when halign is set for other values. When one bar is too close to the border, this type of problem occurs.
Beta Was this translation helpful? Give feedback.
All reactions