<jupyter_start><jupyter_text>Create Better Graphs with BokehThis guide walks through the process of creating better graphs with [bokeh](http://bokeh.pydata.org/en/latest/). The coolest thing about bokeh is that it lets you create interactive plots. We will test out this functionality below.  Basic PlottingAs always, lets begin by importing the libraries that we will be using for this tutorial.<jupyter_code>import numpy as np
from scipy.integrate import odeint
from bokeh.plotting import figure, show
from bokeh.io import output_notebook<jupyter_output><empty_output><jupyter_text>You'll notice that we didn't import the entire bokeh library, rather, we imported specific modules and methods. This is to prevent your python script from using up more computation time and memory than is necessary. Bokeh is a large library, and importing the entire package is rather reckless. The first thing that we are going to do is allow the bokeh library to produce graphs in a python notebook.<jupyter_code>output_notebook()<jupyter_output><empty_output><jupyter_text>Now lets plot something pretty. To start with, we are going to plot a [Lorenz System](https://www.wikiwand.com/en/Lorenz_system). The code below is taken from a [bokeh demo](http://bokeh.pydata.org/en/latest/docs/gallery/lorenz.html)<jupyter_code>sigma = 10
rho = 28
beta = 8.0/3
theta = 3 * np.pi / 4

def lorenz(xyz, t):
    x, y, z = xyz
    x_dot = sigma * (y - x)
    y_dot = x * rho - x * z - y
    z_dot = x * y - beta* z
    return [x_dot, y_dot, z_dot]

initial = (-10, -7, 35)
t = np.arange(0, 100, 0.006)

solution = odeint(lorenz, initial, t)

x = solution[:, 0]
y = solution[:, 1]
z = solution[:, 2]
xprime = np.cos(theta) * x - np.sin(theta) * y

colors = ["#C6DBEF", "#9ECAE1", "#6BAED6", "#4292C6", "#2171B5", "#08519C", "#08306B",]

p = figure(title="lorenz example")

p.multi_line(np.array_split(xprime, 7), np.array_split(z, 7),
             line_color=colors, line_alpha=0.8, line_width=1.5)
show(p)  # open a browser<jupyter_output><empty_output><jupyter_text>Interactive PlottingIn order to make these plots interactive in a jupyter notebook, we make one more import.<jupyter_code>from ipywidgets import interact
from bokeh.io import push_notebook<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10447100486941124, 'fraction_numerical': 0.02478972996901284, 'mean_word_length': 4.678391959798995, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '361960', 'license': 'MIT', 'n_tokens_mistral': 808, 'n_tokens_neox': 766, 'n_words': 267, 'path': 'Guides/python/betterGraphs-bokeh.ipynb', 'repo_name': 'rocketproplab/Guides', 'size': '2259'}