Skip to content

Extra whitespace with SVG export #8046

Description

@msalvaris

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions