Skip to content

Instantly share code, notes, and snippets.

@jjhelmus
Created April 14, 2014 02:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jjhelmus/10610995 to your computer and use it in GitHub Desktop.
Save jjhelmus/10610995 to your computer and use it in GitHub Desktop.
Plotting Polar data with Bokeh
# 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()
@jackparmer
Copy link

You could also try this with Plotly's open-source Python library, code here:
https://plot.ly/pandas/polar-chart/
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment