Practical Python - A plot in your browser with Bokeh

Practical Python - A plot in your browser with Bokeh

Python is a simple but powerful language, and comes with a wealth of libraries. The chart above took just 9 lines of Python. All the hard work is done by the Bokeh library. It shows the chart in your browser, where you can zoom in and move around the chart.

from bokeh.plotting import figure, show

import math

x_values = range(0, 720)

y_values = [math.sin(math.radians(x)) for x in x_values]

p = figure(title='10 Sine waves', x_axis_label='x (degrees)', \
y_axis_label='y = sin(x)', plot_width=850, plot_height=350)

for i in range(10):

   factor = 1 - i/10

   p.line(x_values, [y * factor for y in y_values])


show(p)

For more information, including a line by line explanation of the code below, see the full blog post

To view or add a comment, sign in

More articles by Coen de Groot

  • Python - Count and learn

    Here is a simple problem: Count how many times each character occurs in a string. And one more thing: Do this using…

    14 Comments
  • Python support - Ask wisely, ask nicely

    What do you do if you need some Python support, from a quick answer to affordable regular mentoring or tutoring? Python…

    2 Comments
  • Control your computer using Python

    Python is an excellent language for taking control of your computer and performing some of the more tedious tasks. I…

  • A quick and simple GUI in Python

    Python is an easy-to-learn but powerful language, and comes with a wealth of libraries. It is often used to create…

  • Playful Python - Simple recursion with Python Turtles

    Python is a simple but powerful language, and comes with a wealth of libraries. The black line of the image above took…

  • Practical Python - Updating spreadsheets

    How would you like to grab a share price daily, and store it in a spreadsheet? Or add a new column to dozens of…

  • Practical Python - Easy fractions

    When you ask your spreadsheet to calculate 1/2 + 1/3 you get something like this: This is obviously an approximation…

    1 Comment
  • Practical Python in 10 lines - Retrieve and display a data set

    Python is a simple but powerful language, and comes with a wealth of libraries. The chart above took just 10 lines of…

Explore content categories