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

bar plot multi_level=False issues with Bokeh backend in Safari #5672

Closed
michi42 opened this issue Mar 31, 2023 · 8 comments · Fixed by #5755
Closed

bar plot multi_level=False issues with Bokeh backend in Safari #5672

michi42 opened this issue Mar 31, 2023 · 8 comments · Fixed by #5755
Labels
tag: backend: bokeh type: bug Something isn't correct or isn't working

Comments

@michi42
Copy link

michi42 commented Mar 31, 2023

Setting multi_level=False for a bar plot sets major_label_text_font_size = 0pt (see https://github.com/holoviz/holoviews/blob/main/holoviews/plotting/bokeh/chart.py#L802). This does not work well in Safari which simply ignores "too small" fonts, leading to displayed, overlapping labels (see screenshot below).

As an alternative one could set major_label_text_alpha to 0, major_label_text_line_height to 0 and major_label_text_font_size to 1px to hide the labels:

props['major_label_text_font_size'] = '1px'
props['major_label_text_alpha'] = 0
props['major_label_text_line_height'] = 0

Possibly there could also be a nicer solution, avoiding these hacks to hide the labels altogether, using major_label_overrides or a custom ticker?

image

@hoxbro
Copy link
Member

hoxbro commented Apr 11, 2023

Can you share a minimal, reproducible example (MRE)?

I would like to fiddle around with the settings myself.

@hoxbro hoxbro added type: bug Something isn't correct or isn't working tag: backend: bokeh labels Apr 11, 2023
@michi42
Copy link
Author

michi42 commented Apr 23, 2023

Apologies for the delay...

This triggers the problem for me with holoviews==1.14.9, bokeh==2.4.2, hvplot==0.8.0.

import pandas as pd
import holoviews as hv
import hvplot.pandas
hv.extension('bokeh')
pdf = pd.DataFrame({"ATLAS":{"Mar":1.0,"Apr":2.0},"CMS":{"Mar":3.0,"Apr":4.0}})
plt = pdf.hvplot(kind='bar', responsive=True, height=430).opts(multi_level=False)
hv.save(plt, 'sample.html', backend='bokeh')

Depending on the Safari version, it either renders with the second-level labels not hidden as expected (recent safari versions) or even breaks completely rendering with "invalid bbox" (older versions):
image

Adding the following hook works around the issue for all Safari versions I tested:

def hv_single_level_barplot_workaround(plot, element):
    xaxis = plot.handles['xaxis']
    if (not plot.multi_level) and xaxis.major_label_text_font_size == '0pt':
        xaxis.major_label_text_font_size = '1px'  # safari does not like 0pt
        xaxis.major_label_text_alpha = 0
        xaxis.major_label_text_line_height = 0

@hoxbro
Copy link
Member

hoxbro commented May 26, 2023

This looks fine for me running Holoviews=1.16:

Bokeh 2.4.3
image

Bokeh 3.1.1
image

@philippjfr
Copy link
Member

Looks broken in 3.1.1 looking at your screenshot above.

@philippjfr
Copy link
Member

See also #5726

@hoxbro
Copy link
Member

hoxbro commented May 26, 2023

I was mainly talking about the missing font, but yes, the bar is broken in 3.1.1.

@michi42
Copy link
Author

michi42 commented May 27, 2023

Also in 2.4.3 the output is not correct in Safari, although it's not that obvious: multi_level=False should suppress the second-level category axis ("ATLAS" / "CMS" in my example). This is actually what is shown in the screenshot in the first post.

The expected output would be this:
image

@hoxbro
Copy link
Member

hoxbro commented Jun 11, 2023

I finally understood the problem... I have opened a PR with your suggested fix. Thank you for your patience. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tag: backend: bokeh type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants