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

Extra whitespace with SVG export #8046

Closed
msalvaris opened this issue Jul 3, 2018 · 4 comments · Fixed by #10402
Closed

Extra whitespace with SVG export #8046

msalvaris opened this issue Jul 3, 2018 · 4 comments · Fixed by #10402

Comments

@msalvaris
Copy link

This was initially reported in the Google groups channel and was encouraged to open an issue here

ALL software version info (bokeh, python, notebook, OS, browser, any other relevant packages)

Ubuntu 16.04
Python 3.6 (Conda env)
Jupyter notebook 5.5
Bokeh 0.13.0
Firefox (although shouldn't matter)

Description of expected behavior and the observed behavior

When exporting a multilevel categorical barchart to SVG it seems to introduce extra whitespace between the levels. This extra whitespace is also apparent in the legend. The effect is worse for longer labels as though the padding is linked to the number of characters in the label.

Complete, minimal, self-contained example code that reproduces the issue

fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
years = ['2015-01-01', '2016-01-01', '2017-01-01']

data = {'fruits' : fruits,
        '2015-01-01'   : [2, 1, 4, 3, 2, 4],
        '2016-01-01'   : [5, 3, 3, 2, 4, 6],
        '2017-01-01'   : [3, 2, 4, 4, 5, 3]}

# this creates [ ("Apples", "2015"), ("Apples", "2016"), ("Apples", "2017"), ("Pears", "2015), ... ]
x = [ (fruit, year) for fruit in fruits for year in years ]
counts = sum(zip(data['2015-01-01'], data['2016-01-01'], data['2017-01-01']), ()) # like an hstack

year = [i[1] for i in x]

# Normal output
source = ColumnDataSource(data=dict(x=x, counts=counts, year=year))
p = figure(x_range=FactorRange(*x), plot_height=400, plot_width=800, title="Fruit Counts by Year",
           toolbar_location=None, tools="")

p.vbar(x='x', top='counts', width=0.9, source=source, legend='year')

p.y_range.start = 0
p.x_range.range_padding = 0.1
p.xaxis.major_label_orientation = 1.2
p.xgrid.grid_line_color = None

show(p)

#SVG output
source = ColumnDataSource(data=dict(x=x, counts=counts,year=year))
p = figure(x_range=FactorRange(*x), plot_height=400, plot_width=800, title="Fruit Counts by Year",output_backend="svg",
           toolbar_location=None, tools="")

p.vbar(x='x', top='counts', width=0.9, source=source, legend='year')

p.y_range.start = 0
p.x_range.range_padding = 0.1
p.xaxis.major_label_orientation = 1.2
p.xgrid.grid_line_color = None

export_svgs(p, filename="plot.svg")

A notebook and the html output of the notebook can be found here:
https://gist.github.com/msalvaris/3bebd4027a2fe9ba7b428f18ac310ced

@Haptein
Copy link

Haptein commented Jul 9, 2018

Have you tried the following?
p.background_fill_color = None
p.border_fill_color = None

It is briefly mentioned in the docs that you need to do this in order to get transparent backgrounds. Although it'd be nice if this was the default with svg exports.

@msalvaris
Copy link
Author

Hm, no but I don't think my issue is with transparency it is that there is extra whitespace between the levels in the plots when exporting to SVG. This is also apparent in the legend.

@bryevdv
Copy link
Member

bryevdv commented Jul 9, 2018

@canavandl do you have any ideas off the top of your head?

@phausamann
Copy link
Contributor

phausamann commented Dec 4, 2018

I would also like to highlight the fact that the axis line width and the ticks are thicker and the last tick seems to be gray instead of black.

This is also independent of the export, any plot with a FactorRange and output_backend='svg' seems to have this problem.

@mattpap mattpap modified the milestones: short-term, 2.3 Aug 16, 2020
@mattpap mattpap mentioned this issue Aug 17, 2020
8 tasks
@mattpap mattpap modified the milestones: 2.3, 2.2 Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants