# \[ANN\] Bokeh.jl, another plotting library!

**URL:** https://discourse.julialang.org/t/ann-bokeh-jl-another-plotting-library/81070
**Category:** Package Announcements
**Tags:** plotting
**Created:** [May 14, 2022, 6:54pm UTC](https://discourse.julialang.org/t/ann-bokeh-jl-another-plotting-library/81070 "2022-05-14T18:54:04Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)
#### Post date: [May 14, 2022, 6:54pm UTC](https://discourse.julialang.org/t/ann-bokeh-jl-another-plotting-library/81070/1 "2022-05-14T18:54:04Z")

</div>

# [Bokeh.jl](https://github.com/cjdoris/Bokeh.jl)

[Because](https://github.com/JuliaPlots/Plots.jl) [there](https://github.com/JuliaPlots/Makie.jl) [just](https://github.com/JuliaPlots/PlotlyJS.jl) [aren’t](https://github.com/JuliaPlots/UnicodePlots.jl) [enough](http://gadflyjl.org/stable/) [plotting](https://github.com/queryverse/VegaLite.jl) [libraries](https://github.com/JuliaPy/PyPlot.jl) [for](https://github.com/mbaz/Gaston.jl) [Julia](https://github.com/jheinen/GR.jl), I made [**another one**](https://github.com/cjdoris/Bokeh.jl).

This one wraps BokehJS, which is the JavaScript component of the [python Bokeh package](https://bokeh.org) (though it doesn’t actually call Python). It can render plots in a notebook or straight to your browser.

You can make interactive plots, add widgets and build up complex layouts. Interaction with a backing server is not implemented (yet).

TTFP is about 5 seconds on my machine, which somehow beats UnicodePlots (7 seconds).

What’s neat is that it is mostly automagically generated from the Python package, which means it supports all the same models, has all the same parameters and defaults, and has loads of documentation that I didn’t have to write.

Very much work in progress, but check out the [**gallery**](https://cjdoris.github.io/Bokeh.jl/stable/gallery/), the [**documentation**](https://cjdoris.github.io/Bokeh.jl/) and the [**repo**](https://github.com/cjdoris/Bokeh.jl).

 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/1/219efeee624f74b990a01d598b4d337088f8c77e.jpeg)

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [May 15, 2022, 7:08pm UTC](https://discourse.julialang.org/t/ann-bokeh-jl-another-plotting-library/81070/2 "2022-05-15T19:08:30Z")

</div>

Does Bokeh.jl allow binding Julia callbacks to plot widgets? And if so, would you have a MWE? Thank you.

---

<div class="post-metadata">

### Author: ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)
#### Post date: [May 15, 2022, 8:09pm UTC](https://discourse.julialang.org/t/ann-bokeh-jl-another-plotting-library/81070/3 "2022-05-15T20:09:56Z")

</div>

No I’m afraid not, the only interactivity is in-browser right now. It’s planned for the future but not any time soon.

You can probably cobble something together yourself using WebIO.jl and some custom JavaScript. If you did I’d love to see it.

---

<div class="post-metadata">

### Author: ![mig](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mig/32/36443_2.png) [@mig](https://discourse.julialang.org/u/mig)
#### Post date: [May 20, 2022, 6:34pm UTC](https://discourse.julialang.org/t/ann-bokeh-jl-another-plotting-library/81070/4 "2022-05-20T18:34:11Z")

</div>

You mentioned that this was generated “automagically” from the Python source code. Did you use a tool, such as a transpiler, to convert it?  
Thank you.

---

<div class="post-metadata">

### Author: ![RoyiAvital](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/royiavital/32/571_2.png) [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)
#### Post date: [May 20, 2022, 10:14pm UTC](https://discourse.julialang.org/t/ann-bokeh-jl-another-plotting-library/81070/5 "2022-05-20T22:14:00Z")

</div>

`Bokeh.jl` is the closest thing to MATLAB’s experience I have seen so far.  
It can handle large data set while maintaining interactivity. Still not as fast as MATLAB but I haven’t seen anything else in Julia that can do this:

```julia
using Bokeh;
Bokeh.settings!(use_browser = true);
hF = figure(tooltips = [("x", "\$x"), ("y", "\$y")]); #<! The tooltips allow hovering over data to see its values
numPts = 1_000_000;
plot!(hF, Scatter, x = randn(numPts), y = randn(numPts));
display(hF); #<! Opens in a browser

```

Well Done!

---

<div class="post-metadata">

### Author: ![liuyxpp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liuyxpp/32/9870_2.png) [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)
#### Post date: [May 21, 2022, 2:58am UTC](https://discourse.julialang.org/t/ann-bokeh-jl-another-plotting-library/81070/6 "2022-05-21T02:58:12Z")

</div>

Oh dear, I have waited so long and finally, there it is! I can now convert my Bokeh scripts to Julia. Thanks so much!

---

<div class="post-metadata">

### Author: ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)
#### Post date: [May 21, 2022, 6:41pm UTC](https://discourse.julialang.org/t/ann-bokeh-jl-another-plotting-library/81070/7 "2022-05-21T18:41:04Z")

</div>

> [@mig](#):
>
> You mentioned that this was generated “automagically” from the Python source code. Did you use a tool, such as a transpiler, to convert it?

No, nothing that clever. The Python package has [a script](https://github.com/bokeh/bokeh/blob/2.4.2/scripts/spec.py) which outputs information about all the Bokeh models (the components of a plot, such as axes, glyphs, data, legends, tools, etc.). My Julia package uses [a modified version of the script](https://github.com/cjdoris/Bokeh.jl/blob/main/spec/generate.py) and then [parses the resulting JSON at precompile-time to generate all the models](https://github.com/cjdoris/Bokeh.jl/blob/main/src/spec.jl).

The same system is used to ensure the named colours, colour palettes, and some other pieces of information are consistent with the Python version. All the other functionality is still written in Julia.

---

<div class="post-metadata">

### Author: ![Gabrielforest](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gabrielforest/32/27538_2.png) [@Gabrielforest](https://discourse.julialang.org/u/Gabrielforest)
#### Post date: [May 31, 2022, 9:19pm UTC](https://discourse.julialang.org/t/ann-bokeh-jl-another-plotting-library/81070/8 "2022-05-31T21:19:32Z")

</div>

Hi! The gallery link from your post is broken, although I could easily find it maybe you would like to edit it…  
Thanks for sharing!

---

<div class="post-metadata">

### Author: ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)
#### Post date: [May 31, 2022, 9:56pm UTC](https://discourse.julialang.org/t/ann-bokeh-jl-another-plotting-library/81070/9 "2022-05-31T21:56:58Z")

</div>

Thank you, I’ve fixed the link now. I recently released a new version which changed the layout of the docs.

---

<div class="post-metadata">

### Author: ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)
#### Post date: [June 1, 2022, 6:20pm UTC](https://discourse.julialang.org/t/ann-bokeh-jl-another-plotting-library/81070/10 "2022-06-01T18:20:20Z")

</div>

# Release: Bokeh v0.4.0 / BokehBlink v0.1.0

- Much improved [documentation](https://cjdoris.github.io/Bokeh.jl/stable/) (thanks to @JohnnyChen94 for helping with the [gallery](https://cjdoris.github.io/Bokeh.jl/stable/gallery/)).
- Plotting to browser now works in WSL.
- New package `BokehBlink` provides a backend to display plots in a standalone window ([docs here](https://cjdoris.github.io/Bokeh.jl/stable/misc/#Blink)).
- `BokehBlink.save()` can be used to generate an image of your plot.
- Helper functions for binning data for hexagonal grids (see [this example](https://cjdoris.github.io/Bokeh.jl/stable/gallery/Basic/hex_tile/#hex_tile)).

---

<div class="post-metadata">

### Author: ![astrobc1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/astrobc1/32/45632_2.png) [@astrobc1](https://discourse.julialang.org/u/astrobc1)
#### Post date: [July 6, 2022, 9:21pm UTC](https://discourse.julialang.org/t/ann-bokeh-jl-another-plotting-library/81070/11 "2022-07-06T21:21:46Z")

</div>

Is it possible to export a figure to a standalone .html file? I’ve tried the following, but it 1. asks me to confirm ingoing/outgoing connections each time, and the resulting .html files are not properly formatted.

```julia
using Bokeh, BokehBlink, Blink
# Bokeh.settings!(display=:browser) # Tried with and without

x = [1, 2, 3, 4]
y = sin.(x)

p = Bokeh.figure()
Bokeh.plot!(p, Bokeh.Line, x=x, y=y)
BokehBlink.save("testplot.html", p, format="webp")

```

---

<div class="post-metadata">

### Author: ![astrobc1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/astrobc1/32/45632_2.png) [@astrobc1](https://discourse.julialang.org/u/astrobc1)
#### Post date: [July 7, 2022, 1:47am UTC](https://discourse.julialang.org/t/ann-bokeh-jl-another-plotting-library/81070/12 "2022-07-07T01:47:19Z")

</div>

Update: I’m sure there’s a cleaner method, but for now I accomplished this with the following:

```julia
function savebokehhtml(fname, p)
    doc = Bokeh.Document(p)
    dochtml = Bokeh.doc_standalone_html(doc)
    dochtml_split = split(dochtml, "</head>");
    dochtml_temp = String[]
    push!(dochtml_temp, dochtml_split[1])
    push!(dochtml_temp, """\n<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-2.4.1.min.js"></script>\n""")
    push!(dochtml_temp, dochtml_split[2])
    dochtml_out = join(dochtml_temp)
    open(fname, "w") do io
        write(io, dochtml_out)
    end
end

```

---

<div class="post-metadata">

### Author: ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)
#### Post date: [July 7, 2022, 6:29am UTC](https://discourse.julialang.org/t/ann-bokeh-jl-another-plotting-library/81070/13 "2022-07-07T06:29:24Z")

</div>

Yep the latter way is the right way, but you shouldn’t need to add any extra scripts, `Bokeh.doc_standalone_html(doc)` should already be a self-contained document. If that’s not working for you, please post an issue on the GitHub repo.
