import pandas as pd
import seaborn as sns
%matplotlib inline
sns.set_style('darkgrid')
def pipe(self, func, *args, **kwargs):
if hasattr(func, 'pipe_arg'):
kwargs[func.pipe_arg] = self
return func(*args, **kwargs)
return func(self, *args, **kwargs)
pd.DataFrame.pipe = pipe
sns.violinplot.pipe_arg = 'data'
iris = sns.load_dataset('iris')
sns.violinplot(x='species', y='sepal_width', data=iris)
<matplotlib.axes._subplots.AxesSubplot at 0x11047ec10>
sns.violinplot('species', 'sepal_width', data=iris)
<matplotlib.axes._subplots.AxesSubplot at 0x110813050>
iris.pipe(sns.violinplot, 'species', 'sepal_width')
<matplotlib.axes._subplots.AxesSubplot at 0x110aed890>
iris.pipe(sns.violinplot, x='species', y='sepal_width')
<matplotlib.axes._subplots.AxesSubplot at 0x110bc4a50>