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

[FEATURE] SVG export for gridplot #9169

Closed
birdsarah opened this issue Aug 18, 2019 · 5 comments · Fixed by #10402 or #10713
Closed

[FEATURE] SVG export for gridplot #9169

birdsarah opened this issue Aug 18, 2019 · 5 comments · Fixed by #10402 or #10713

Comments

@birdsarah
Copy link
Member

birdsarah commented Aug 18, 2019

Currently export of a gridplot works for export png but not for svg.

With svg you get a series of plots back and have to manually compile.

User jcacbelos on discourse seems to have a start at something that works: https://discourse.bokeh.org/t/generate-svg-images-from-bokeh-plots-and-include-them-in-a-pdf-report-with-using-svglib-and-reportlab/3889

@chesucr
Copy link
Contributor

chesucr commented Aug 19, 2019

I am "jcacabelos"

Actually I export the plots as SVG files individually, with the export_svgs function. Then I create a PDF file including all of them, not a SVG file.

But what you want is to export an unique SVG file with all the plots in a gridplot right? Or you just want to export them one by one (the same you do with the PNG files)? I think having both options would be a nice feature

@mattpap
Copy link
Contributor

mattpap commented Aug 19, 2019

Currently export of a gridplot works for export png but not for svg.

The "export" part should be emphasized, because otherwise bokeh can't save a gridplot as a PNG, only as a sequence of PNGs. This is because gridplot's implementation doesn't live up to its name and produces a composite layout. We can export such layout as a single PNG, because export utility captures a screenshot of an entire page where a gridplot was rendered.

When issue #3821 is fixed, which is currently work in progress scheduled for bokeh 1.4, it will be possible to put multiple plots on a single canvas, which in turn will allow to save multiple plots a single file (PNG or SVG). At bokeh 2.0, gridplot() will produce an instance of a single canvas GridPlot model. The old behavior will still be possible with an existing GridBox layout.

@mattpap mattpap added this to the 2.0 milestone Aug 19, 2019
@bryevdv
Copy link
Member

bryevdv commented Aug 19, 2019

At bokeh 2.0, gridplot() will produce an instance of a single canvas GridPlot model.

We will have to conduct some experiments to validate that single-canvas performance is acceptable, first.

@birdsarah
Copy link
Member Author

birdsarah commented Aug 19, 2019

At bokeh 2.0, gridplot() will produce an instance of a single canvas GridPlot model.
We will have to conduct some experiments to validate that single-canvas performance is acceptable, first.

This is very exciting.

Regarding performance I would be happy to accept poor performance in the case where I was trying to do an svg export.

Happy to help test / chip in on that!

Thanks for the clarification @chesucr. the pdf arrangement is useful to me while other solutions are coming along but it sounds like @mattpap is working up a proper solution.

@bryevdv
Copy link
Member

bryevdv commented Aug 24, 2020

Looks like there are some issues with this in the 2.2 release packages, re-opening and marking for 2.3 Hopefully not a big lift to fix it up.

Also note that the export_svg function that is not working was not added to the top level bokeh.io module (turned out to be serendipitous) but should be added when this is fixed up.

This is the output I get trying to use the export_svg on the vector.py example updated to use it:

Traceback (most recent call last):
  File "vector.py", line 203, in <module>
    export_svg(gridplot([[p1,p2]], plot_width=400, plot_height=400))  # open a browser
  File "/Users/bryan/anaconda/envs/22pip/lib/python3.8/site-packages/bokeh/io/export.py", line 143, in export_svg
    svgs = get_svg(obj, width=width, height=height, driver=webdriver, timeout=timeout)
  File "/Users/bryan/anaconda/envs/22pip/lib/python3.8/site-packages/bokeh/io/export.py", line 246, in get_svg
    svgs = cast(List[str], web_driver.execute_script(_SVG_SCRIPT))
  File "/Users/bryan/anaconda/envs/22pip/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 634, in execute_script
    return self.execute(command, {
  File "/Users/bryan/anaconda/envs/22pip/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Users/bryan/anaconda/envs/22pip/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.JavascriptException: Message: javascript error: view.export is not a function
  (Session info: headless chrome=84.0.4147.135)

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.

4 participants