Seaborn compatability with mpld3¶

See the mpld3 github for more about mpl3d. See the seaborn docs for more about seaborn.

Last updated December 30, 2013

In [1]:
import numpy as np
from numpy.random import randn
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from mpld3 import display_d3

In [2]:
np.random.seed(0)

In [3]:
def sinplot(flip=1):
x = np.linspace(0, 14, 100)
for i in range(1, 7):
plt.plot(x, np.sin(x + i * .5) * (7 - i) * flip)

In [4]:
x1 = randn(80)
x2 = randn(80)
x3 = x1 * x2
y1 = .5 + 2 * x1 - x2 + 2.5 * x3 + 3 * randn(80)
y2 = .5 + 2 * x1 - x2 + 2.5 * randn(80)
y3 = y2 + randn(80)
g = np.random.choice(list("ABC"), 80)
y_logistic = 1 / (1 + np.exp(-y1))
y_flip = [np.random.binomial(1, p) for p in y_logistic]
df = pd.DataFrame(dict(x1=x1, x2=x2, x3=x3, y1=y1, y2=y2, y3=y3, y_flip=y_flip, g=g))
d = randn(100, 30)


Basic aesthetics¶

In [5]:
sinplot()

In [6]:
sinplot()
display_d3()

Out[6]:
In [7]:
sns.set(style="whitegrid")
sinplot()

In [8]:
sinplot()
display_d3()

Out[8]:
In [9]:
sns.set(style="nogrid")
sinplot()

In [10]:
sinplot()
display_d3()

Out[10]:

Linear model plots¶

In [11]:
sns.set()

In [12]:
sns.lmplot("x1", "y2", df)
fig = plt.gcf()

In [13]:
display_d3(fig)

Out[13]:
In [14]:
sns.lmplot("x1", "y2", df, col="g", size=3.5)
fig = plt.gcf()

In [15]:
display_d3(fig)

Out[15]:
In [16]:
sns.lmplot("x1", "y2", df, color="g")
fig = plt.gcf()

In [17]:
display_d3(fig)

/Users/mwaskom/anaconda/lib/python2.7/site-packages/mpld3-0.0.1-py2.7.egg/mpld3/_objects.py:378: UserWarning: legend is not implemented: it will be ignored

Out[17]:
In [18]:
sns.regplot("x1", "y1", df)
fig = plt.gcf()

In [19]:
display_d3(fig)

Out[19]:
In [20]:
sns.coefplot("y1 ~ x1 * x2 + g", df)
fig = plt.gcf()

In [21]:
display_d3(fig)

Out[21]:
In [22]:
sns.interactplot("x1", "x2", "y1", df)
fig = plt.gcf()

In [23]:
display_d3(fig)

/Users/mwaskom/anaconda/lib/python2.7/site-packages/mpld3-0.0.1-py2.7.egg/mpld3/_objects.py:375: UserWarning: artists not implemented.  Elements will be ignored

Out[23]: