Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

jackparmer commented Feb 22, 2016

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