Open orausch opened 1 month ago
Hi, you can add padding around the plot panel (on top specifically) using the panel_inset
parameter in theme()
. But in this case you will have to increase the plot vertical size as well:
+ theme(panel_inset=[400, 0, 0]) + ggsize(600, 1000)
Similar effect can be achieve by setting wider y-scale limits or larger "extent".
However, the better solution in my opinion would be to customize the tooltip layout, for example:
value_format_list = [f'{k}=@{k}' for k in list(string.ascii_lowercase)]
format_str = ',\n'.join(', '.join(value_format_list[i:i+4]) for i in range(0, len(value_format_list), 4))
format_str
'a=@a, b=@b, c=@c, d=@d,\ne=@e, f=@f, g=@g, h=@h,\ni=@i, j=@j, k=@k, l=@l,\nm=@m, n=@n, o=@o, p=@p,\nq=@q, r=@r, s=@s, t=@t,\nu=@u, v=@v, w=@w, x=@x,\ny=@y, z=@z'
ggplot(d, aes(x='a', y='b')) + geom_point(tooltips=layer_tooltips().line(format_str))
Ah panel_inset
seems great, thanks!
However, it seems to interact weirdly with facet_wrap
:
from lets_plot import *
LetsPlot.setup_html()
d = {
l: [i]*3 for i, l in enumerate(string.ascii_lowercase)
} | {'facet': [0, 1, 2]}
ggplot(d, aes(x='a', y='b')) + geom_point(tooltips=layer_tooltips(list(string.ascii_lowercase))) + theme(panel_inset=[400, 0, 0]) + ggsize(800, 1500) + facet_wrap("facet")
Some issues I see:
Any idea what's up with that?
'facet': [0, 1, 2]
: the series size here should be the sane as in the data (i.e. 26)
Upd: maybe not, it depends on what you want to achieve. Y-axis labels seem wrong indeed.
Maybe better try scale_y_continuous(limits=..)
or scale_y_continuous(expand=..)
to have adequate empty space above the point.
expanding the limit doesn't work with this toy example (since I only have one datapoint 😛 ), but would probably be sufficient in real plots.
If #1187 were fixed that would also be sufficient since facets usually have enough space below
expanding the limit doesn't work with this toy example
To make it work you need to make plot larger (taller). But why don't you try to re-format the tooltip's content to make it more compact?
Yep to be clear that's a good suggestion and I've starting using that, thanks!
my tooltips are still pretty beefy despite that, but it definitely helps.
Similar to #1187, it's tricky to use plots with lots of tooltips. Unlike #1187 I think this case might require some API changes?
For example, maybe there some way to add padding around the plot such that the tooltips would display?