5

Maintainers note: this question is obsolete. Calling multiple glyph methods on a figure automatically combines (and has for many years). For information on modern Bokeh, see:

https://docs.bokeh.org/en/latest/docs/user_guide/plotting.html



OBSOLETE:

I am running the Bokeh tutorial in the IPython notebook. It only displays the scatter plot and not the line plot. From the command-line it renders both plots separately.

How do I get both graphs in the same chart, on top of each other?

import numpy as np
import bokeh.plotting as bplt
bplt.output_file("bokehtest.html")
#bplt.output_notebook(url=None)
x = np.linspace(-2*np.pi, 2*np.pi, 100)
y = np.cos(x)
bplt.line(x, y, color="red")
bplt.scatter(x, y, marker="square", color="blue")
bplt.show()
2
  • @Jack, "bokeh" is a photography term hijacked by the library. There are plenty of questions about image processing and creating the bokeh effect here. Without something to specify that it's a library in Python, people are going to abuse it. Remember, nobody actually reads wiki excerpts... Commented Dec 12, 2013 at 3:17
  • @Charles You didn't filter out answers from that list; and only a handful of the remaining questions actually talk about the effect itself. Commented Dec 12, 2013 at 3:31

2 Answers 2

3

OBSOLETE ANSWER: see https://docs.bokeh.org/en/latest/docs/user_guide/output/jupyter.html#jupyter-interactors* for modern Bokeh



You just need to call bplt.hold() before any of the plotting commands, to toggle the "hold state". The following code works for me:

import numpy as np
import bokeh.plotting as bplt
bplt.output_file("bokehtest.html")
#bplt.output_notebook(url=None)
x = np.linspace(-2*np.pi, 2*np.pi, 100)
y = np.cos(x)
bplt.hold()  # <--- The important line!!
bplt.line(x, y, color="red")
bplt.scatter(x, y, marker="square", color="blue")
bplt.show()
Sign up to request clarification or add additional context in comments.

1 Comment

Page by URL for answer for modern Bokeh shows 404.
1

OBSOLETE ANSWER: see https://docs.bokeh.org/en/latest/docs/user_guide/plotting.html for modern Bokeh



Try using the figure command like in this example:

import numpy as np
import bokeh.plotting as bplt
bplt.output_file("bokehtest.html")
x = np.linspace(-2*np.pi, 2*np.pi, 100)
y = np.cos(x)

bplt.figure()
bplt.line(x, y, color="red")
bplt.scatter(x, y, marker="square", color="blue")
bplt.show()

1 Comment

No... right now I have them in the same cell and they come out in two different charts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.