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
Add user guide documentation for bokeh.io.export #6292
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
34456de
initial docs commit
canavandl-test 956387a
add svg docs
canavandl-test 1fa19a7
Merge branch 'master' into canavandl/6290_export_documentation
canavandl-test c87d6ee
fix bad path
canavandl-test 335fe8d
Add SVG example and tweaks
canavandl-test 0dd923b
Move higher in user guide
canavandl-test 0983a19
Make suggested edits
canavandl-test File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
.. _userguide_export: | ||
|
||
Exporting Plots | ||
=============== | ||
|
||
.. _userguide_export_png: | ||
|
||
PNG Generation | ||
-------------- | ||
|
||
Bokeh can generate RGBA-format Portable Network Graphics (PNG) images from | ||
layouts using the |export| function. This functionality uses a headless browser | ||
called WebKit to render the layout in memory and then capture a screenshot. The | ||
generated image will be of the same dimensions as the source layout. | ||
|
||
In order to create a PNG with a transparent background, users should set the | ||
``Plot.background_fill_color`` and ``Plot.border_fill_color`` properties to | ||
``None``. | ||
|
||
Limitations | ||
~~~~~~~~~~~ | ||
|
||
Responsive sizing_modes may generate layouts with unexpected size and aspect | ||
ratios. It is recommended to use the default ``fixed`` sizing mode. Also, | ||
glyphs that are rendered via webgl won't be included in the generated PNG, so | ||
it's suggested to use the default ``Plot.webgl=True`` attribute. | ||
|
||
Additional dependencies | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
In order to use the |export| function, users have to install some additional | ||
dependencies. These dependencies can be installed via conda: | ||
|
||
.. code-block:: sh | ||
|
||
conda install selenium phantomjs pillow | ||
|
||
Alternatively, you can install phantomjs from npm via | ||
|
||
.. code-block:: sh | ||
|
||
npm install -g phantomjs-prebuilt | ||
|
||
Example usage | ||
~~~~~~~~~~~~~ | ||
|
||
Usage is similar to the |save| and |show| functions. | ||
|
||
.. code-block:: python | ||
|
||
from bokeh.io import export | ||
|
||
export(plot, filename="plot.png") | ||
|
||
.. image:: /_images/unemployment.png | ||
|
||
.. _userguide_export_svg: | ||
|
||
SVG Generation | ||
-------------- | ||
|
||
Bokeh also supports replacing the HTML5 Canvas plot output with an SVG element | ||
that can be edited in image editing programs such as Adobe Illustrator and/or | ||
converted to PDFs. This functionality uses a JavaScript library called | ||
canvas2svg to mock the normal Canvas element and its methods with an SVG | ||
element. | ||
|
||
The SVG output isn't as performant as the default Canvas backend when it comes | ||
to rendering large number of glyphs or handling lots of user interactions like | ||
panning. | ||
|
||
Like PNGs, in order to create a SVG with a transparent background, users | ||
should set the ``Plot.background_fill_color`` and ``Plot.border_fill_color`` | ||
properties to ``None``. | ||
|
||
Limitations | ||
~~~~~~~~~~~ | ||
|
||
It's not possible to create a single SVG for a layout of plots, as each plot | ||
is it's own distinct SVG element. Alternatively, it's possible to download a | ||
SVG plot using a SaveTool from the toolbar. However, currently an SVG export | ||
of a plot with a toolbar will have a blank area where the toolbar was rendered | ||
in the browser. | ||
|
||
Example usage | ||
~~~~~~~~~~~~~ | ||
|
||
The SVG backend is activated by setting the ``Plot.output_backend`` attribute | ||
to ``"svg"``. | ||
|
||
.. code-block:: python | ||
|
||
# option one | ||
plot = Plot(output_backend="svg") | ||
# option two | ||
plot.output_backend = "svg" | ||
|
||
.. image:: /_images/unemployment.svg | ||
|
||
Exporting a SVG Image | ||
~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The simplest way to export a SVG plot is to install a browser bookmarklet from | ||
the New York Times called `SVG-Crowbar`_. When clicked, it runs a snippet of | ||
JavaScript and adds a prompt on the page to download the plot. It's written to | ||
work with Chrome and should work with Firefox in most cases. | ||
|
||
Alternatively, it's possible to download a SVG plot using the ``SaveTool``, but | ||
the toolbar isn't captured though it figures into the plot layout solver | ||
calculations. It's not great, but a workable option. | ||
|
||
.. |export| replace:: :func:`~bokeh.io.export` | ||
.. |save| replace:: :func:`~bokeh.io.save` | ||
.. |show| replace:: :func:`~bokeh.io.show` | ||
|
||
.. _SVG-Crowbar: http://nytimes.github.io/svg-crowbar/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence is a bit awkward, maybe:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed