Skip to content

Commit

Permalink
Custom widgets. Documentation + bball example
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Beaumont committed Sep 8, 2014
1 parent b36b4fb commit 6c975a5
Show file tree
Hide file tree
Showing 16 changed files with 801 additions and 187 deletions.
25 changes: 25 additions & 0 deletions doc/_static/bball_viewer_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from glue import custom_viewer

from matplotlib.colors import LogNorm

bball = custom_viewer('Shot Plot',
x='att(x)',
y='att(y)')


@bball.plot_data
def show_hexbin(axes, x=None, y=None, style=None, **kwargs):
return axes.hexbin(x.values, y.values,
cmap='Purples',
gridsize=40,
norm=LogNorm(),
mincnt=1)


@bball.plot_subset
def show_points(axes, x=None, y=None, style=None, **kwargs):
return axes.plot(x.values, y.values, 'o',
alpha=style.alpha,
mec=style.color,
mfc=style.color,
ms=style.markersize)
52 changes: 52 additions & 0 deletions doc/_static/bball_viewer_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from glue import custom_viewer

from matplotlib.colors import LogNorm
from matplotlib.patches import Circle, Rectangle, Arc
from matplotlib.lines import Line2D

bball = custom_viewer('Shot Plot',
x='att(x)',
y='att(y)')


@bball.plot_data
def show_hexbin(axes, x=None, y=None, style=None, **kwargs):
return axes.hexbin(x.values, y.values,
cmap='Purples',
gridsize=40,
norm=LogNorm(),
mincnt=1)


@bball.plot_subset
def show_points(axes, x=None, y=None, style=None, **kwargs):
return axes.plot(x.values, y.values, 'o',
alpha=style.alpha,
mec=style.color,
mfc=style.color,
ms=style.markersize)


@bball.setup
def draw_court(ax):

c = '#777777'
opts = dict(fc='none', ec=c, lw=2)
hoop = Circle((0, 63), radius=9, **opts)
ax.add_patch(hoop)

box = Rectangle((-6 * 12, 0), 144, 19 * 12, **opts)
ax.add_patch(box)

inner = Arc((0, 19 * 12), 144, 144, theta1=0, theta2=180, **opts)
ax.add_patch(inner)

threept = Arc((0, 63), 474, 474, theta1=0, theta2=180, **opts)
ax.add_patch(threept)

opts = dict(c=c, lw=2)
ax.add_line(Line2D([237, 237], [0, 63], **opts))
ax.add_line(Line2D([-237, -237], [0, 63], **opts))

ax.set_ylim(0, 400)
ax.set_aspect('equal', adjustable='datalim')
65 changes: 65 additions & 0 deletions doc/_static/bball_viewer_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from glue import custom_viewer

from matplotlib.colors import LogNorm
from matplotlib.patches import Circle, Rectangle, Arc
from matplotlib.lines import Line2D
import numpy as np

bball = custom_viewer('Shot Plot',
x='att(x)',
y='att(y)',
bins=(10, 100),
hitrate=False,
color=['Reds', 'Purples'],
hit='att(shot_made)')


@bball.plot_data
def show_hexbin(axes, x=None, y=None, style=None,
hit=None, hitrate=None, color=None, bins=None, **kwargs):
if hitrate:
return axes.hexbin(x.values, y.values, hit.values,
reduce_C_function=lambda x: np.array(x).mean(),
cmap=color,
gridsize=bins,
mincnt=5)
else:
return axes.hexbin(x.values, y.values,
cmap=color,
gridsize=bins,
norm=LogNorm(),
mincnt=1)


@bball.plot_subset
def show_points(axes, x=None, y=None, style=None, **kwargs):
return axes.plot(x.values, y.values, 'o',
alpha=style.alpha,
mec=style.color,
mfc=style.color,
ms=style.markersize)


@bball.setup
def draw_court(ax):

c = '#777777'
opts = dict(fc='none', ec=c, lw=2)
hoop = Circle((0, 63), radius=9, **opts)
ax.add_patch(hoop)

box = Rectangle((-6 * 12, 0), 144, 19 * 12, **opts)
ax.add_patch(box)

inner = Arc((0, 19 * 12), 144, 144, theta1=0, theta2=180, **opts)
ax.add_patch(inner)

threept = Arc((0, 63), 474, 474, theta1=0, theta2=180, **opts)
ax.add_patch(threept)

opts = dict(c=c, lw=2)
ax.add_line(Line2D([237, 237], [0, 63], **opts))
ax.add_line(Line2D([-237, -237], [0, 63], **opts))

ax.set_ylim(0, 400)
ax.set_aspect('equal', adjustable='datalim')
77 changes: 77 additions & 0 deletions doc/_static/bball_viewer_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from glue import custom_viewer
from glue.core.subset import RoiSubsetState

from matplotlib.colors import LogNorm
from matplotlib.patches import Circle, Rectangle, Arc
from matplotlib.lines import Line2D
import numpy as np

bball = custom_viewer('Shot Plot',
x='att(x)',
y='att(y)',
bins=(10, 100),
hitrate=False,
color=['Reds', 'Purples'],
hit='att(shot_made)')


@bball.make_selector
def make_selector(roi, x=None, y=None, **data):

state = RoiSubsetState()
state.roi = roi
state.xatt = x.id
state.yatt = y.id

return state


@bball.plot_data
def show_hexbin(axes, x=None, y=None, style=None,
hit=None, hitrate=None, color=None, bins=None, **kwargs):
if hitrate:
return axes.hexbin(x.values, y.values, hit.values,
reduce_C_function=lambda x: np.array(x).mean(),
cmap=color,
gridsize=bins,
mincnt=5)
else:
return axes.hexbin(x.values, y.values,
cmap=color,
gridsize=bins,
norm=LogNorm(),
mincnt=1)


@bball.plot_subset
def show_points(axes, x=None, y=None, style=None, **kwargs):
return axes.plot(x.values, y.values, 'o',
alpha=style.alpha,
mec=style.color,
mfc=style.color,
ms=style.markersize)


@bball.setup
def draw_court(ax):

c = '#777777'
opts = dict(fc='none', ec=c, lw=2)
hoop = Circle((0, 63), radius=9, **opts)
ax.add_patch(hoop)

box = Rectangle((-6 * 12, 0), 144, 19 * 12, **opts)
ax.add_patch(box)

inner = Arc((0, 19 * 12), 144, 144, theta1=0, theta2=180, **opts)
ax.add_patch(inner)

threept = Arc((0, 63), 474, 474, theta1=0, theta2=180, **opts)
ax.add_patch(threept)

opts = dict(c=c, lw=2)
ax.add_line(Line2D([237, 237], [0, 63], **opts))
ax.add_line(Line2D([-237, -237], [0, 63], **opts))

ax.set_ylim(0, 400)
ax.set_aspect('equal', adjustable='datalim')
Binary file added doc/bball_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/bball_2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/bball_3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/bball_4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/bball_5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6c975a5

Please sign in to comment.