Created
March 31, 2015 04:10
-
-
Save ChrisBeaumont/e719f04e12d5f6a8eac3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import numpy as np | |
from glue import custom_viewer, qglue | |
pcoord = custom_viewer('Parallele Coordinates') | |
def _plot_pcoords(axes, dataframe, **kwargs): | |
colnames = dataframe.columns | |
x = np.arange(len(colnames)) | |
artists = [] | |
for line in dataframe.values: | |
artists.extend(axes.plot(x, line, '-', **kwargs)) | |
axes.set_xticks(x) | |
axes.set_xticklabels(colnames) | |
return artists | |
@pcoord.plot_data | |
def plot_data(axes, layer): | |
df = layer.to_dataframe()[['sepal_length', 'sepal_width', | |
'petal_length', 'petal_width']] | |
df = (df - df.mean()) / df.std() | |
return _plot_pcoords(axes, df, color='k', alpha=.3, lw=2) | |
@pcoord.plot_subset | |
def plot_subset(axes, layer, style): | |
df = layer.data.to_dataframe() | |
df = df[['sepal_length', 'sepal_width', | |
'petal_length', 'petal_width']] | |
df = (df - df.mean()) / df.std() | |
df = df[layer.to_mask()] | |
return _plot_pcoords(axes, df, color=style.color, alpha=.5, lw=3) | |
qglue(data='iris.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment