msmbuilder / msmexplorer

Data visualizations for biomolecular dynamics
http://msmbuilder.org/msmexplorer/
MIT License
17 stars 17 forks source link

Implement Joy Plots #101

Closed cxhernandez closed 7 years ago

cxhernandez commented 7 years ago

They're trendy and a good option for discrete time-series analysis of distributions. I imagine this would be nice to look at features evolving along a transition pathway.

Also fairly simple to implement:

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="white", rc={"axes.facecolor": (0, 0, 0, 0)})

# Create the data
rs = np.random.RandomState(42)
x = rs.randn(500)
g = np.tile(list("ABCDEFGHIJ"), 50)
df = pd.DataFrame(dict(x=x, g=g))
m = df.g.map(ord)
df["x"] += m

# Initialize the FacetGrid object
pal = sns.cubehelix_palette(10, rot=-.25, light=.7)
g = sns.FacetGrid(df, row="g", hue="g", aspect=12, size=.5, palette=pal)

# Draw the densities in a few steps
g.map(sns.kdeplot, "x", clip_on=False, shade=True, alpha=1, lw=1.5, bw=.2)
g.map(sns.kdeplot, "x", clip_on=False, color="w", lw=2, bw=.2)
g.map(plt.axhline, y=0, lw=2, clip_on=False)

# Define and use a simple function to label the plot in axes coordinates
def label(x, color, label):
    ax = plt.gca()
    ax.text(0, .2, label, fontweight="bold", color=color, 
            ha="left", va="center", transform=ax.transAxes)

g.map(label, "x")

# Set the subplots to overlap
g.fig.subplots_adjust(hspace=-.25)

# Remove axes details that don't play will with overlap
g.set_titles("")
g.set(yticks=[])
g.despine(bottom=True, left=True)

image

mpharrigan commented 7 years ago

why is this called a joy plot

cxhernandez commented 7 years ago

From ggjoy:

The name "joyplot" was proposed by Jenny Bryan on Twitter on April 24, 2017, in reference to the iconic cover art for Joy Division's album Unknown Pleasures.

mpharrigan commented 7 years ago

:eyeroll:

cxhernandez commented 7 years ago

Not a fan of Joy, I see.

msultan commented 7 years ago

:man_facepalming:

cxhernandez commented 7 years ago

Thoughts on this?

image

The idea is to have many features in the same plot over several states. @msultan thinks it's a little busy though.

msultan commented 7 years ago

Something like this could be might be more clearer? My fear is that people tend to interpret a single axis as representing the same variable. image

cxhernandez commented 7 years ago

Is this better?

image

cxhernandez commented 7 years ago

done in #102