Last active
August 29, 2015 14:23
-
-
Save brendancol/a021c1146ccd7753e401 to your computer and use it in GitHub Desktop.
bokeh geographic scatter plot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import os | |
import sys | |
import pandas | |
from pysal.weights.Distance import DistanceBand | |
import numpy | |
numpy.random.seed(10) | |
import bokeh | |
from bokeh.plotting import figure, show, output_file | |
from bokeh.models import Range1d | |
def plot_csv(csv_path, headers=('x','y','z_score')): | |
df = pandas.read_csv(csv_path) | |
df.columns = headers | |
ramp = list(reversed(['#a50026','#d73027','#f46d43','#fdae61','#fee090','#e0f3f8','#abd9e9','#74add1','#4575b4','#313695'])) | |
df['fill'] = [ramp[l] for l in pandas.qcut(numpy.array(df['z_score'].values.tolist()), 10).labels] | |
x = df['x'].values.tolist() | |
y = df['y'].values.tolist() | |
radii = [8] * len(x) | |
colors = df['fill'].values.tolist() | |
TOOLS="crosshair,pan,wheel_zoom,box_zoom,reset" | |
output_file("bokeh-geo-scatter.html", title="bokeh_geographic_scatter_plot.py example") | |
xn, yn, xm, ym = df['x'].min(), df['y'].min(), df['x'].max(), df['y'].max() | |
p = figure(tools=TOOLS, plot_width=1000, plot_height=600, title=None, toolbar_location="below") | |
p.y_range = Range1d(yn, ym) | |
p.x_range = Range1d(xn, xm) | |
p.circle(x, y, size=2, color=colors, alpha=0.55) | |
show(p) | |
if __name__ == '__main__': | |
output_points_csv = 'gedis_ord_result.csv' | |
plot_csv(output_points_csv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment