Skip to content
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

Tooltips overrunning the plot #1188

Open
orausch opened this issue Sep 16, 2024 · 7 comments
Open

Tooltips overrunning the plot #1188

orausch opened this issue Sep 16, 2024 · 7 comments

Comments

@orausch
Copy link

orausch commented Sep 16, 2024

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?

from lets_plot import *
LetsPlot.setup_html()

d = {
    l: [i] for i, l in enumerate(string.ascii_lowercase)
}
ggplot(d, aes(x='a', y='b')) + geom_point(tooltips=layer_tooltips(list(string.ascii_lowercase))) + ggsize(300, 200)
Screenshot 2024-09-16 at 8 21 35 AM
@alshan
Copy link
Collaborator

alshan commented Sep 16, 2024

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)

image

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))

image

@orausch
Copy link
Author

orausch commented Sep 16, 2024

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:

  • It doesn't seem to add the inset anymore
  • the y-axis labels seem to be placed incorrectly?
Screenshot 2024-09-16 at 1 31 29 PM

Any idea what's up with that?

@alshan
Copy link
Collaborator

alshan commented Sep 16, 2024

'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.

@alshan
Copy link
Collaborator

alshan commented Sep 16, 2024

Maybe better try scale_y_continuous(limits=..) or scale_y_continuous(expand=..) to have adequate empty space above the point.

@orausch
Copy link
Author

orausch commented Sep 17, 2024

Screenshot 2024-09-17 at 6 51 38 AM 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

@alshan
Copy link
Collaborator

alshan commented Sep 17, 2024

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?

@orausch
Copy link
Author

orausch commented Sep 17, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants