Skip to content

Instantly share code, notes, and snippets.

@fogonthedowns
Last active April 27, 2016 20:31
Show Gist options
  • Select an option

  • Save fogonthedowns/431d1144acbcfe3a3c9d72343b6d43c2 to your computer and use it in GitHub Desktop.

Select an option

Save fogonthedowns/431d1144acbcfe3a3c9d72343b6d43c2 to your computer and use it in GitHub Desktop.
bokeh plotting with column data source
import pandas as pd
from bokeh.plotting import ColumnDataSource, figure, output_file, show
from bokeh.models import HoverTool
output_file("scatter.html")
df = pd.read_csv('/Users/jzollars/07_isolate_selection.csv')
hash = {}
c = ('aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black',
'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse',
'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan',
'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta', 'darkolivegreen',
'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray',
'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue',
'firebrick', 'floralwhite', 'forestgreen', 'fuchsia', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod',
'gray', 'green', 'greenyellow', 'grey', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki',
'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan',
'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen',
'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'lime', 'limegreen',
'linen', 'magenta', 'maroon', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen',
'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose',
'moccasin', 'navajowhite', 'navy', 'oldlace', 'olive', 'olivedrab', 'orange', 'orangered', 'orchid', 'palegoldenrod',
'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue',
'purple', 'red', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna',
'silver', 'skyblue', 'slateblue', 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan', 'teal',
'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'white', 'whitesmoke', 'yellow', 'yellowgreen');
#loop through and assign colors:
counter = 0
for a in df.material.unique():
hash[a] = c[counter]
counter += 1
# generate colors:
colors = [hash[code] for code in df.material]
df['color'] = colors
source = ColumnDataSource(df)
TOOLS="pan,wheel_zoom,box_zoom,reset,hover"
p = figure(title="Hoverful Scatter", tools=TOOLS)
p.circle('isolate.concentration', 'purity.score', radius=.66, source=source,
fill_color=colors, fill_alpha=0.6, line_color=None)
hover = p.select(dict(type=HoverTool))[0]
hover.tooltips = [
("material", "@material")
]
show(p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment