Created
April 14, 2014 02:10
-
-
Save jjhelmus/10610995 to your computer and use it in GitHub Desktop.
Plotting Polar data with Bokeh
This file contains 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
# Plot polar data using Bokeh | |
# Author: Jonathan J. Helmus | |
import numpy as np | |
from bokeh.plotting import * | |
# Data in polar coordinates | |
azimuths = np.linspace(0, 2 * np.pi, 20) | |
ranges = np.array([2, 4, 6, 8]) | |
# convert to x and y meshes | |
azimuths_m, ranges_m = np.meshgrid(azimuths, ranges) | |
xx = ranges_m * np.cos(azimuths_m) | |
yy = ranges_m * np.sin(azimuths_m) | |
# array of color values | |
C = np.random.randint(0, 10, xx.shape) | |
colors = brewer["Spectral"][10] | |
def pcolor(C, xx, yy): | |
""" Create a pseudocolor like-plot. Note the last points in C ignored. """ | |
xx_count, yy_count = xx.shape | |
for j in range(yy_count-1): | |
for i in range(xx_count-1): | |
ys = (yy[i, j], yy[i, j+1], yy[i+1, j+1], yy[i+1, j]) | |
xs = (xx[i, j], xx[i, j+1], xx[i+1, j+1], xx[i+1, j]) | |
fill_color = colors[C[i, j]] | |
patch(ys, xs, fill_color=fill_color) | |
# create plot | |
output_file("sample.html", title="Sample example") | |
hold() | |
pcolor(C, xx, yy) | |
show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could also try this with Plotly's open-source Python library, code here:
https://plot.ly/pandas/polar-chart/