bokeh not showing in jupyter notebook - jupyter-notebook

I am unable to plot even the most basic of Bokeh plots in Jupyter Notebook. I had a search and can see that this was a reported problem a little over a year ago but nothing since - is it still an issue for others?
from bokeh.io import output_notebook, show
from bokeh.plotting import figure
output_notebook()
p = figure(plot_width=400, plot_height=400)
p.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=15, line_color="navy",
fill_color="orange", fill_alpha=0.5)
show(p)
I get the "BokehJS 0.12.10 successfully loaded." message, but not plot. Note that it outputs html files ok.
I've tried changing the environment variables using:
import os
os.environ['BOKEH_RESOURCES'] = 'inline'
But this has not effect either. It's bee a frustrating afternoon so any help would be appreciated!

Running the lines below worked for me
from bokeh.resources import INLINE
import bokeh.io
from bokeh import *
bokeh.io.output_notebook(INLINE)

My guess is that your version of the notebook is too old. There is no technical path to simultaneously supporting both the new JupyterLab and classic notebook versions older than 5.0, at all. Supporting JupyterLab is an imperative, so as of recently, Bokeh can only support classic notebook 5.0 and newer. So, you can:
downgrade Bokeh (<= 10.12.8), or
updgrade Jupyter Notebook (>= 5.0), or
switch to recent JupyterLab betas. You will need to install the Jupyter extension with
jupyter labextension install jupyterlab_bokeh

Related

PyCharm: Show .png in markdown cell in Jupyter notebook file

I am using PyCharm 2019.2 Professional and I am trying to figure out how to display a .png file within a markdown cell. My file is located in a subfolder called screenshots.
I tried the following line of code; however, PyCharm will not display the image. I just see an empty rectangle.
![test.png](screenshots/test.png]
After 4 short years, JetBrains finally fixed this issue in PyCharm 2021.3 EAP. The patch will not be ported to 2021.2 or earlier versions. See this thread.
If you're using an older PyCharm version and don't feel like updating right now, here is a dirty hack to print images on a grid in your notebook in PyCharm using matplotlib:
import matplotlib.pyplot as plt
f, ax = plt.subplots(1, 3)
ax[0].imshow(plt.imread('iguanas1.png'))
ax[1].imshow(plt.imread('iguanas2.png'))
ax[2].imshow(plt.imread('iguanas3.png'))

I can not execute pptk.viewer() on google colab

I can not visualize point clouds with pptk on google colab. It stays running permanently and I have to stop it manually.
It does work with Jupyter, but I wanted to use it on colab.
What I'm doing is just this:
import numpy as np
import pptk
x = np.random.rand(100, 3)
v = pptk.viewer(x)
v.set(point_size=0.0001)
I am also installing pptk with:
!pip install pptk
Does anybody knows why isn't it working?
Thank you!

How do I get HoloViews to display in Google Colabs notebooks?

I can't get any HoloViews graphics to display in any Google Colabs notebook.
For example even the simple Bokeh example right out fo the HoloViews introduction
points = hv.Points(np.random.randn(500,2))
points.hist(num_bins=51, dimension=['x','y'])
fails to show anything, without any error being reported, while the same code (and all example code from HoloViews) works fine in local Jupyter notebooks.
If I download the Colabs notebook locally and open it, I see the following where I say nothing for output in Colabs:
No (safe) renderer could be found for output. It has the following MIME types: application/javascript, application/vnd.bokehjs_load.v0+json
How do I get Bokeh HoloViews to display in Google Colabs notebooks?
See https://github.com/pyviz/holoviews/issues/3551 . Colaboratory has some serious limitations on how it handles notebooks, and for now you have to do this once:
import os, holoviews as hv
os.environ['HV_DOC_HTML'] = 'true'
Then for every single cell with a plot in it you have to re-load the JS:
hv.extension('bokeh')
hv.Curve([1, 2, 3])
It would be great if Google could fix that, as it's unworkable in my opinion.

loading bokehJS in jupyter lab

I am having a strange behavior with bokeh library.
So apparently, I am trying to create some beautiful plots with bokeh. When I try to load the bokeh in JupyterLab, I get constant, "Loading bokehJS..." message but if I try to plot with jupyter (from bokeh.io import output_notebook, show output_notebook()), I could plot it. It looks like lab has some issues? or am I not using lab properly?
comparative screenshot attached. Dark (JupyterLab), Light(Jupyter Notebook)
You likely need to install the jupyterlab_bokeh extension:
https://docs.bokeh.org/en/latest/docs/user_guide/notebook.html#jupyterlab

Is it possible to use nbconvert to export a Bokeh plot to a single html file?

I tried to use nbconvert > HTML and it returns random bokeh logos
here is my code:
import pandas as pd
from bokeh.plotting import *
output_notebook()
df = pd.DataFrame({'rev':[234,345,657,7]})
df
line(df['rev'],df['rev'], color="red", line_width=2,
title="Archimean", legend="Archimedean")
show()
A small CSS bug made it into 0.5.0 that affects nbconvert output. There is alread a fix checked into master. We will be releasing 0.5.1 early next week.

Resources