Skip to content

Commit

Permalink
added some snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
blaylockbk committed Aug 3, 2023
1 parent 9279827 commit 2501d55
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
8 changes: 5 additions & 3 deletions rose/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def bar(self, **kwargs):

return ax

def plot(self, spacing=3, figsize=(7, 6), colors="viridis", **kwargs):
def plot(self, ax=None, spacing=3, figsize=(7, 6), colors="viridis", **kwargs):
"""Plot the binned data as a windrose
Parameters
Expand Down Expand Up @@ -121,8 +121,10 @@ def plot(self, spacing=3, figsize=(7, 6), colors="viridis", **kwargs):
nsectors, nbins = table.shape
radian_locs = np.arange(0, np.pi * 2, np.pi * 2 / len(table))

fig = plt.figure(figsize=figsize)
ax = plt.subplot(projection="polar")
if ax is None:
fig = plt.figure(figsize=figsize)
ax = plt.subplot(projection="polar")

ax.set_theta_zero_location("N") # theta=0 at the top
ax.set_theta_direction(-1) # theta increasing clockwise

Expand Down
23 changes: 23 additions & 0 deletions rose/snippets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
Some helpful snippets for pandas-rose.
"""
import numpy as np
import matplotlib.pyplot as plt

def labels_on_top(ax):
"""Put radius labels on top of the bar plot."""
for i in ax.get_yticks()[::2]:
# TODO: determine if values on ax are normed
#if table_kwargs.get("normed", None):
# text = f"{i:.1%}"
#else:
# text = f"{i:g}"
text = i
ax.text(np.pi / 16, i, text, zorder=100, ha="center")
ax.set_yticklabels([])
return ax

def generate_polar_subplots(nrows, ncols):
"""Generate a matrix of polar subplots"""
return plt.subplots(nrows, ncols, subplot_kw=dict(projection="polar"))

0 comments on commit 2501d55

Please sign in to comment.