TODOs

  • Should set many parameters to None (e.g., slice_by and idx)
  • Bug with empty string hover_text
  • update traces method
  • drop_attr method which performs an update by removing an attribute
  • access trace list as attribute
  • annotation methods, expecially in bar charts
  • break up splicer functions
  • method to return traces indexed by name (might be useful)
  • add points/lines e.g. add y=3 line, and allow to add by date or categorical point too
  • Ribbon plots
  • Error bars
  • Subplots shouldn't have dedicated figure, should call an update method, or, have methods that return static figure that doesn't get updated

In [4]:
import sys
import numpy as np
import pandas as pd
import plotly
import plotly.graph_objs as go

sys.path.append('/Users/csempek/root/repos/personal/splice/')
import splice
import splice.splice_objs as so

import plotly.offline as off
off.init_notebook_mode(connected=True)



In [5]:
np.random.seed(111)
df = pd.DataFrame({
    'idx': np.arange(1000) % 100,
    'num': np.random.random(1000),
    'cat1': ['ABCD'[np.random.randint(0, 4)] for _ in range(1000)],
    'cat2': [['male', 'female'][np.random.randint(0, 2)] for _ in range(1000)],
    'cat3': [['child', 'teen', 'adult'][np.random.randint(0, 3)] for _ in range(1000)],
    })

In [40]:
bar = so.GroupedBars(df=df, x='cat1', y='num', 
                     slice_by=['cat2', 'cat3'],
                     idx=['cat2', 'cat3'],
                     hover_text=['cat1', 'cat2', 'cat3'],
                     marker={'line': {'color':'gray', 'width':0.5}}
                    )

In [41]:
off.iplot(bar.figure)



In [42]:
bar.subplots(cols=2)
off.iplot(bar.subplot_figure)


This is the format of your plot grid:
[ (1,1) x1,y1 ]  [ (1,2) x2,y2 ]
[ (2,1) x3,y3 ]  [ (2,2) x4,y4 ]
[ (3,1) x5,y5 ]  [ (3,2) x6,y6 ]


In [45]:
bar = so.StackedBars(df=df, x='cat1', y='num', 
                     slice_by=['cat2', 'cat3'],
                     idx=['cat2'],
                     hover_text=['cat1', 'cat2', 'cat3'],
                     marker={'line': {'color':'gray', 'width':0.5}}
                    )

In [47]:
off.iplot(bar.figure)



In [46]:
bar.subplots(cols=2)
off.iplot(bar.subplot_figure)


This is the format of your plot grid:
[ (1,1) x1,y1 ]  [ (1,2) x2,y2 ]


In [ ]: