I want to use a loop to load and/or modify data and plot the result within the loop using Bokeh (I am familiar with Matplotlib's axes.color_cycle
). Here is a simple example
import numpy as np from bokeh.plotting import figure, output_file, show output_file('bokeh_cycle_colors.html') p = figure(width=400, height=400) x = np.linspace(0, 10) for m in xrange(10): y = m * x p.line(x, y, legend='m = {}'.format(m)) p.legend.location='top_left' show(p)
which generates this plot
How do I make it so the colors cycle without coding up a list of colors and a modulus operation to repeat when the number of colors runs out?
There was some discussion on GitHub related to this, issues 351 and 2201, but it is not clear how to make this work. The four hits I got when searching the documentation for cycle color
did not actually contain the word cycle
anywhere on the page.
plotting : A high level interface for creating visual glyphs. The dataset used for generating bokeh graphs is collected from Kaggle. To create scatter circle markers, circle() method is used. To create a single line, line() method is used.
You can hide the lines by setting their grid_line_color to None .
It is probably easiest to just get the list of colors and cycle it yourself using itertools
:
import numpy as np from bokeh.plotting import figure, output_file, show # select a palette from bokeh.palettes import Dark2_5 as palette # itertools handles the cycling import itertools output_file('bokeh_cycle_colors.html') p = figure(width=400, height=400) x = np.linspace(0, 10) # create a color iterator colors = itertools.cycle(palette) for m, color in zip(range(10), colors): y = m * x p.line(x, y, legend='m = {}'.format(m), color=color) p.legend.location='top_left' show(p)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With