Open jwhendy opened 2 months ago
One more interesting finding: on a whim I tried just theme(text=element_text(ha='right'))
and it appears to apply to all text except the strip_text (not sure what it's doing to the y-axis label as that moves left; I'd have expected closer to the y-axis if "right" is in the global frame, or to the top if "right" is with respect to the y-axis orientation).
p + theme(text=element_text(ha='right'))
@has2k1 could I try and help with this? If so, I can look around but wondered if you knew off hand somewhere else ha
is applied the I can study for reference?
Thanks!
@jwhendy, you can if you make sense of it.
Normally matplotlib handles the horizontal alignment and it aligns along an edge. Here we have to repurpose the alignment to be a justification within the strip_box
. And for maximum flexibility we have to accommodate alignment values in the [0, 1]
range.
For example, ha
and va
are applied here to align the title
, subtitle
, caption
, axis_title_x
and axis_title_y
with respect to the plot panels.
We also have to deal with the margin
, but that can come later.
@has2k1 I admit my experience with more sophisticated/formal python projects is not good. I had some ideas, but struck out even figuring out how to access the ha
argument passed via theme(strip_text_x=element_text(ha='right')
.
I have little/no experience with the **kwargs
dict or inheritance like the super()
call. I ended up just adding a print(info.ha)
to the code when things weren't working like I thought, and even when specifying ha='right'
it still prints out as center
. How does ha
make it to StripText
?
I am definitely willing to keep trying, but don't want to burden you with coaching me. I defer to your time and patience :)
From the title alignment, my baby step was going to be:
self._x = l + w * f
self.set_horizontalalignment(anchor)
where anchor=ha should workha
values yetI had some ideas, but struck out even figuring out how to access the
ha
argument passed viatheme(strip_text_x=element_text(ha='right')
.
The values of info.ha
and info.va
are not being picked up and passed through. For now assume you have the right ha
values and proceed with the rest. As you test you can hard code info.ha = "left"
, info.ha = 0.2
, e.t.c
@has2k1 ah, that makes me feel slightly better :)
Here's an first attempt at my fork. Some comments:
ha
, I made the call that if < 0.5, we should anchor left, otherwise anchor right. Not sure if that's reasonable or how it should workmargin
variable (maybe pad
or padding
would be a more accurate name) of 0.05
to keep the text off the edge by w * 0.05
. I could see setting this to 0 if ha
is a float so the user is given absolute positioning control.Test code, switching line 66 to test:
import pandas as pd
from plotnine import *
df = pd.DataFrame({'x': [0, 1, 2, 3], 'y': [4, 5, 6, 7],
'facet': ['abcdef', 'abcdef', 'ghijkl', 'ghijkl']})
p = ggplot(df, aes(x='x', y='y')) + geom_point() + facet_grid('~facet')
p
With info.ha = "left"
:
With info.ha = "right"
:
With info.ha = 0.8
:
Create a PR and we continue there.
@has2k1 I drafted it but then paused. I branched off of main
; do you want me to rebase on dev
before I PR?
Branching off main is the way to go.
I think I ran into the same as #506 . Repro:
Default facet strip_text:
Theming
element_text
to try and applyha='right'
, I get the same result:Using
ha='left'
yields the same:I also tried explicitly using
strip_text_x
(andstrip_text_y
, cause why not try it all) and saw no effect. I also triedfacet_grid
instead offacet_wrap
just to be thorough and saw the same behavior as above.I'm on OS X, with
plotnine==0.13.6
. I was on0.13.0
when I wrote this, upgraded, restarted my jupyter kernel, and reproduced again to verify it's not been fixed, at least in the released version.