Skip to content

Wrapper around matplotlib and seaborn for better transparency and unified experience

License

Notifications You must be signed in to change notification settings

sizhky/plotlib2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

%load_ext autoreload
%autoreload 2
from plotlib.main import plot, snsplot, plt, sns
import numpy as np

Call any sns/matplotlib plot throught the plot function

Use the function itself as a kwarg with the parameters to be plotted as a tuple

plot(hist=np.random.randn(1000)); plt.show()
plot(scatter=(np.random.randn(100), np.random.randn(100)))

png

<matplotlib.collections.PathCollection at 0x7fa83f101610>

png

Combine Plots

plot(imshow=np.random.randn(500,500)*255,
     scatter=(np.random.randn(100)*100, np.random.randn(100)*100))
<matplotlib.collections.PathCollection at 0x7fa83f028190>

png

Use kwargs for more control

plot(hist={'x': np.random.randn(10000), 'bins': 100},
     scatter={'x': np.random.randn(80), 'y': 40+10*np.arange(-4, 4, step=0.1)+np.random.randn(80), 'c': 'red'},); plt.show()

plot(boxplot={'x': np.random.randn(1000), 'vert': False});

png

png

Same style for sns plotting as well

snsplot(set={'style':"darkgrid"})
snsplot(distplot={'a': np.random.randn(1000), 'hist': False, 'kde_kws':{"color": "k", "lw": 3, "label": "KDE"}})
<matplotlib.axes._subplots.AxesSubplot at 0x7fa83efccc50>

png

%%time
fmri = sns.load_dataset("fmri")
snsplot(relplot={'x':"timepoint", 'y':"signal", 'hue':"event", 'style':"event",
            'col':"subject", 'col_wrap':5,
            'height':3, 'aspect':.75, 'linewidth':2.5,
            'kind':"line", 'data':fmri.query("region == 'frontal'")})
CPU times: user 2.06 s, sys: 9.42 ms, total: 2.06 s
Wall time: 2.06 s





<seaborn.axisgrid.FacetGrid at 0x7fa83cb0a950>

png

Easy for automating plots via code

  • i is reserved for axis.
fig, ax = plot(close='all', subplots=(2, 2, {'figsize': (10,10)}))
ax = iter(ax.flat)
font = {'fontsize':10}

plot(
    i=next(ax),
    set_title=('Number of Videos', font),
    set_xlabel=('Number of Videos', font),
    set_ylabel=('Number of People', font),
    hist=({'x': np.random.randn(1000), 'bins': 0.5+np.arange(-4, 4, 0.1)})
)

plot(
    i=next(ax),
    set_title=('Number of Videos per Person', font),
    set_xlabel=('Number of Videos', font),
    set_ylabel=('Number of People', font),
    hist=({'x': np.random.randn(1000), 'bins': 28})
)

plot(
    i=next(ax),
    scatter=({'x': np.random.randn(1000), 'y': np.random.randn(1000)}),
    set_title=('Distribution of Video Duration', font),
    set_xlabel=('Number of Videos', font),
    set_ylabel=('Number of People', font),
    hist=({'x': np.random.randn(1000), 'bins': 28})
)

plot(
    i=next(ax),
    hist = (np.random.randn(1000), {'bins':28}),
    set_title = ('Distribution of Average Face Sizes ',font),
    **{k:v for k,v in zip(['set_xlabel','set_ylabel'], 
                          [(v,{'fontsize': 10}) for v in 
                           ['Average Face Size [pixels]','Number of Videos']])}
); 

png

About

Wrapper around matplotlib and seaborn for better transparency and unified experience

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages