In python's Bokeh, how can I remove text above the plot? - python

With the following code:
import bokeh.plotting as bplt
bplt.output_file('output.html', mode="cdn")
I get an html file with my graph(s); but it has the text:
You have 1 plots
Close All Plots
Above the graph.
Is there a way to produce html output without this text?

As of Bokeh 0.5 there is a much more convenient embed module, which should provide the functionality you desire.
In your specific case, I would suggest the following setup:
Load BokehJS from CDN at the top of your page (or in the head)
<script src="http://cdn.bokeh.org/bokeh-0.5.1.js"></script>
In the Python script generating the plots, run
bokeh.embed.components(bokeh.plotting.curplot(), bokeh.resources.CDN)
for each plot. That will return a tuple with a <script> string containing the plot generation code, and a <div> string you can place anywhere on your page as a target.

Related

Exporting functional Plotly sunburst plot

Does anyone know how I can export a plotly sunburst plot as a standalone file which can keep all the functionalities, like annotation while hovering and expansion by click?
Visualizing a hierarchical data with plotly.sunburst in python is a beautiful and beneficial way of presenting it in the best order, while you are able to hover the values to see the annotation, click on each parent section to collapse and expand the child values, etc.. But to present the visualized data (plot) independently without having to open the Python notebook, needs the plot to be saved and exported in a standalone file format that allows keeping every functionality available.
Does anyone know how to do this? and what file format can give this luxury to us?
Thanks
Saving to an HTML file will do the trick:
doc

Embedding Bokeh graphs while maintaining linked axis

I have linked the x axis of my bokeh graphs together by simply sharing the same x_range:
graph2.x_range = graph1.x_range
When I zoom-in/out or change the x-axis of one graph in any way, the other graph adjust with it. I really like this functionality.
However, when I embed the bokeh graphs in an html template they are not connected anymore.
script, div = components(graphs).
The components function returns a script that contains the data for your plot and provides a target div to display the plot view.
I added script and div in the placeholders of my html template, which is then loaded with Flask.
Everything works fine, but the graphs are not connected anymore.
It looks like the graps are embedded separately and therefore they cannot be linked together. I wonder if there is a method to do this.
If anyone has had this issue before, pls help :)
I used this documentation:
https://docs.bokeh.org/en/2.4.1/docs/user_guide/embed.html

Generate HTML with plotly graphs and a navbar

I am running a Python pipeline that generates some data files. As a last step of the pipeline, I want to generate a HTML file containing nicely styled graphs representing that data with plotly and a navbar at the top (I will probably have 2 tabs, each one containing different set of charts). This sounds like hard to do with plotly only. How can I achieve this? Should I make an html file with some styling, then just embed the plotly graphs in it? Or should I try to do it solely using plotly?
I did some something similar writing the html (and nav elements) from python and then embedding the charts using the to_html method:
fig.to_html(full_html=False, include_plotlyjs=True)

How to save all plots of bokeh figure in svg and html, not only first one

I am trying to save my bokeh figure in png, svg, and html formats. Figure consists of several lineplots, done in the loop. Svg and html files somehow contain only the first lineplot, although png and html outputs which open in the browser, show all the lineplots.
p = bokeh.plotting.figure(...)
colors = itertools.cycle(palette[10])
for i, color in zip(range(len(exp_labels)), colors):
p.line(
source=data.loc[data['experiment']==exp_labels[i]],
x=x,
y=y,
color=color,
legend=exp_labels[i]
)
bokeh.io.show(p) # figure in the browser shown fine
export_png(p, filename + '.png') # png export works fine
p.output_backend = "svg"
export_svgs(p, filename + '.svg') # svg file shows only first lineplot
bokeh.io.save(p, filename + '.html') # html file also shows only first plot
If svg is unable to record in one file all the plots done in the loop, in spite of that they belong to the same figure p, I am wondering if its possible to somehow plot at once all the plots with .groupby(), since all the data belong to one dataframe, and solve this problem by such an approach.
UPD: Seems like the main problem is svg, and html has problems just because of the changed output_backend. If saved html first, it saved fine. However, it's still unclear how to save svg with all the lineplots, and how to switch output_backend to some default value. I couldn't find documentation for parameters of output_backend
It's entirely possible there is just a bug. As of Bokeh 1.4, SVG support relies on a third party "canvas to SVG" library that is no longer maintained. It will need to be revisited from the ground up at some point, but that is a matter of resources. I would suggest you file a GitHub issue

Select text in Bokeh plot

I would like to be able to search for specific words in my Bokeh plot. Say that I have a very simple plot:
import numpy as np
from bokeh.plotting import figure, show, output_file
x = np.linspace(0, 4*np.pi, 100)
y = np.sin(x)
TOOLS = "pan,wheel_zoom,box_zoom,reset,save,box_select"
p1 = figure(title="Some sample title", tools=TOOLS)
p1.circle(x,y, legend="sin(x)")
output_file("legend.html", title="legend.py example")
show(p1)
Which results in
I would like to be able to search the text in my browser using [ctrl+f] or [cmd+f]. Is there any way to do that? I would like to be able to search for the title and/or for labels, so in this case, example queries would be one of {sample, title,1,0.5}. Of course this example is hypothetical, but I think it's enough to illustrate the question.
Is there any way to use browser search functionality inside a Bokeh plot?
There is no way to do this in Boken currently, as it renders to an HTML5 canvas object, so the browser just sees the final result of the rendering. If you're willing to use Bokeh's sister library HoloViews, it however has a both Bokeh and SVG backend. When rendered through that SVG backend, your browser will then have access to all the text elements.
To help evaluate plotting libraries to see if they're suitable for your purpose, what you're looking for is basically a SVG backend. Usually it's easy to find a list of supported backends in the documentation of each library.
Also note that "having all individual plot elements accessible to the browser" and "plotting a lot of data points" are conflicting goals. The HTML5 canvas backend works well for plotting lots of data (even more so with datashader) partly because it only exposes the final plot image to the browser. If you want to expose the details of your plot to the browser (e.g via the SVG backend), you should expect to see a performance hit at some point if your plots get bigger (more data) or otherwise more complex, compared to the HTML5 canvas backend.
There is no way to do this. Bokeh plots are not textual DOM elements, everything is rendered on an HTML raster canvas, which the browser only sees as an rectangular area of RGBA pixels.

Categories