Repository: napjon/krisk

Issue:
if category, bar plot not shown all index values
See http://nbviewer.jupyter.org/github/napjon/krisk/blob/master/notebooks/themes-colors.ipynb

Not all year index values shown

Discussion:

Patch:
diff --git a/README.md b/README.md
index 0ac2848..2392b25 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,5 @@
 [![CircleCI](https://circleci.com/gh/napjon/krisk.svg?style=shield)](https://circleci.com/gh/napjon/krisk) 
 [![PyPI version](https://badge.fury.io/py/krisk.svg)](https://pypi.python.org/pypi/krisk/)
-[![Coverage Status](https://img.shields.io/codecov/c/github/napjon/krisk/master.svg)](https://codecov.io/gh/napjon/krisk)
 ![svg](https://img.shields.io/github/license/napjon/krisk.svg)
 
 # Overview
diff --git a/krisk/make_chart.py b/krisk/make_chart.py
index 3e73504..9d4656b 100644
--- a/krisk/make_chart.py
+++ b/krisk/make_chart.py
@@ -19,34 +19,27 @@ def round_list(arr):
                 
 def make_chart(df,**kwargs):
     
-    def insert_series_on(f):
-
+    def insert_series_on(f,df=df):
+        data = f(df)
         if category:
             #Iterate and append Data for every category
-            for cat, subset in df.groupby(category):
+            for cat in data.columns:
                 cat = str(cat)
-                insert_data_to_series(f,subset,cat)
+                insert_data_to_series(data[cat], cat)
                 c._option['legend']['data'].append(cat)
         else:
-            insert_data_to_series(f,df)
+            insert_data_to_series(data)
     
     
-    def insert_data_to_series(f,df,cat=None):
-        data = f(df)
+    def insert_data_to_series(data, cat=None):
         series = deepcopy(elem_series)
         series['data'] = round_list(data)
         series['type'] = kwargs['type']
         series['name'] = cat if cat else x
         c._option['series'].append(series)
         
-    
     c = Chart(**kwargs)
-    
-    elem_series = {
-            'name': '',
-            'type': kwargs['type'],
-            'data': []}
-    
+    elem_series = {'name': '', 'type': kwargs['type'], 'data': []}
     x = kwargs['x']
     y = kwargs.get('y')
     category = kwargs['category']
@@ -57,8 +50,7 @@ def make_chart(df,**kwargs):
         """Provide stacked,annotate, area for bar line hist"""
         series = c._option['series']
 
-        d_annotate = {'normal':{'show':True,
-                                'position':'top'}}
+        d_annotate = {'normal':{'show': True, 'position': 'top'}}
 
         if category and kwargs['stacked'] == True:
             for s in series:
@@ -81,75 +73,68 @@ def make_chart(df,**kwargs):
         # TODO: make annotate receive all kinds supported in echarts.
     
     if kwargs['type'] in ['bar','line']:
-       
-        
-        
+
+        @insert_series_on
         def get_bar_line_data(df):
             
-#             c._option['yAxis']['scale'] = True #TODO: Still need to be evaluated
-            
-            if y is None:
-                data = df[x].value_counts()
+            if category:
+                if y is None:
+                    data = pd.crosstab(df[x], df[category])
+                else:
+                    data = df.pivot_table(index=x,values=y,columns=category,
+                                          aggfunc=kwargs['how'],fill_value=0)
             else:
-                data = (df[y]
-                        if kwargs['how'] is None else
-                        df.groupby(x)[y].aggregate(kwargs['how']))
-                
-            c._option['xAxis']['data'] = data.index.values.tolist()
+                if y is None:
+                    data = df[x].value_counts()
+                else:
+                    raise AssertionError('Use y in category instead')
             
-            # TODO: Still need to be evaluated
-#             data = (df[x].value_counts()
-#                     if y is None else
-#                     df.groupby(x)[y].aggregate(kwargs['how']))
+            c._option['xAxis']['data'] = data.index.values.tolist()
             
             return data
             
-        
-        insert_series_on(get_bar_line_data)
         bar_line_hist_condition()
-            
+        
+        
     elif kwargs['type'] == 'hist':
         kwargs['type'] = 'bar'
         
-        
+        @insert_series_on
         def get_hist_data(df):
-            y_val,x_val = np.histogram(df[x],
-                                       bins=kwargs['bins'],
+            
+            y_val,x_val = np.histogram(df[x],bins=kwargs['bins'],
                                        normed=kwargs['normed'])
-            data = pd.Series(y_val)
+            if category:
+                data = pd.DataFrame()
+                for cat, sub in df.groupby(category):
+                    data[cat] =  (pd.cut(sub[x], x_val)
+                                  .value_counts(sort=False, normalize=kwargs['normed']))
+            else:
+                data = pd.Series(y_val)
+                
             bins = x_val.astype(int).tolist()
             c._option['xAxis']['data'] = bins
             
             return data
         
-        insert_series_on(get_hist_data)
         bar_line_hist_condition()
-            
+        
     elif kwargs['type'] == 'scatter':
         
-        c._option['xAxis'] = {'type': 'value',
-                              'name': x,
-                              'max': int(df[x].max())}
-        c._option['yAxis'] = {'type': 'value',
-                              'name': y,
-                              'max': int(df[y].max())}
+        c._option['xAxis'] = {'type': 'value', 'name': x, 'max': int(df[x].max())}
+        c._option['yAxis'] = {'type': 'value', 'name': y, 'max': int(df[y].max())}
         c._option['visualMap'] = []
         
-        
-        
         cols = [x,y]
         size = kwargs['size']
         if size is not None:
-            vmap_template_size = {
-                                    'show': False,
+            vmap_template_size = {'show': False,
                                     'dimension': 2,
                                     'min': 0,
                                     'max': 250,
                                     'precision': 0.1,
-                                    'inRange': {
-                                        'symbolSize': [10, 70]
-                                    }
-                                }
+                                    'inRange': {'symbolSize': [10, 70]}
+                                 }
             vmap_size = deepcopy(vmap_template_size)
             vmap_size['min'] = df[size].min()
             vmap_size['max'] = df[size].max()  
@@ -168,16 +153,20 @@ def make_chart(df,**kwargs):
 #             c._option['visualMap'].append(vmap_saturate)
 #             cols.append(saturate)
 
-        columns = cols+df.columns.difference(cols).tolist()
+        columns = cols + df.columns.difference(cols).tolist()
         c._kwargs_chart_['columns'] = columns
         
-        def get_scatter_data(df):
+        def insert_scatter_data(df):
             data = df[columns]
-#             print(columns)
-            return data
-        
-        insert_series_on(get_scatter_data)
-    
-        
-            
-    return c
+            if category:
+                #Iterate and append Data for every category
+                for cat, subset in data.groupby(category):
+                    cat = str(cat)
+                    insert_data_to_series(subset,cat)
+                    c._option['legend']['data'].append(cat)
+            else:
+                insert_data_to_series(data)
+                
+        insert_scatter_data(df)
+
+    return c
\ No newline at end of file
diff --git a/krisk/plot.py b/krisk/plot.py
index fb5c50c..6de3d18 100644
--- a/krisk/plot.py
+++ b/krisk/plot.py
@@ -1,8 +1,7 @@
 
 from krisk.make_chart import make_chart
 
-def bar(df,x,y=None,category=None,how='count',stacked=False,
-        annotate=None,**kwargs):
+def bar(df,x,y=None,category=None,how='count',stacked=False,annotate=None):
     """
     Parameters
     ----------
@@ -29,7 +28,7 @@ def bar(df,x,y=None,category=None,how='count',stacked=False,
     """
     
     # TODO: add optional argument trendline
-    
+    kwargs = {}
     kwargs['x'] = x
     kwargs['y'] = y
     kwargs['category'] = category
@@ -40,8 +39,7 @@ def bar(df,x,y=None,category=None,how='count',stacked=False,
     
     return make_chart(df,**kwargs)
 
-def line(df,x,y=None,category=None,how=None,stacked=False,area=False,
-         annotate=None,**kwargs):
+def line(df,x,y=None,category=None,how=None,stacked=False,area=False,annotate=None):
     """
     Parameters
     ----------
@@ -66,7 +64,7 @@ def line(df,x,y=None,category=None,how=None,stacked=False,area=False,
     -------
     Chart Object
     """
-    
+    kwargs = {}
     kwargs['x'] = x
     kwargs['y'] = y
     kwargs['category'] = category
@@ -78,8 +76,7 @@ def line(df,x,y=None,category=None,how=None,stacked=False,area=False,
     
     return make_chart(df,**kwargs)
 
-def hist(df,x,category=None,bins=10,normed=False,stacked=False,
-         annotate=None,**kwargs):
+def hist(df,x,category=None,bins=10,normed=False,stacked=False,annotate=None):
     """
     Parameters
     ----------
@@ -103,7 +100,7 @@ def hist(df,x,category=None,bins=10,normed=False,stacked=False,
     -------
     Chart Object
     """
-    
+    kwargs = {}
     kwargs['x'] = x
     kwargs['category'] = category
     kwargs['bins'] = bins
@@ -114,7 +111,7 @@ def hist(df,x,category=None,bins=10,normed=False,stacked=False,
     
     return make_chart(df,**kwargs)
 
-def scatter(df,x,y,size=None,category=None,size_px=(10,70),**kwargs):
+def scatter(df,x,y,size=None,category=None,size_px=(10,70)):
     """
     Parameters
     ----------
@@ -134,6 +131,7 @@ def scatter(df,x,y,size=None,category=None,size_px=(10,70),**kwargs):
     Chart Object
     """
     
+    kwargs = {}
     kwargs['x'] = x
     kwargs['y'] = y
     kwargs['category'] = category


Test patch:
diff --git a/krisk/tests/data/bar.json b/krisk/tests/data/bar.json
index 32e0928..4d92a24 100644
--- a/krisk/tests/data/bar.json
+++ b/krisk/tests/data/bar.json
@@ -1,1 +1,139 @@
-{"xAxis": {"data": [69.12, 70.33, 70.93, 71.1, 71.93, 73.49, 74.74, 76.32, 77.56, 78.83, 80.37, 81.235]}, "series": [{"type": "bar", "data": [9279525.0, 10270856.0, 11000948.0, 12760499.0, 14760787.0, 17152804.0, 20033753.0, 23254956.0, 26298373.0, 29072015.0, 31287142.0, 33333216.0], "stack": "continent", "name": "Africa"}, {"type": "bar", "data": [17876956.0, 19610538.0, 21283783.0, 22934225.0, 24779799.0, 26983828.0, 29341374.0, 31620918.0, 33958947.0, 36203463.0, 38331121.0, 40301927.0], "stack": "continent", "name": "Americas"}, {"type": "bar", "data": [8425333.0, 9240934.0, 10267083.0, 11537966.0, 13079460.0, 14880372.0, 12881816.0, 13867957.0, 16317921.0, 22227415.0, 25268405.0, 31889923.0], "stack": "continent", "name": "Asia"}, {"type": "bar", "data": [1282697.0, 1476505.0, 1728137.0, 1984060.0, 2263554.0, 2509048.0, 2780097.0, 3326498.0, 3075321.0, 3428038.0, 3508512.0, 3600523.0], "stack": "continent", "name": "Europe"}, {"type": "bar", "data": [8691212.0, 9712569.0, 10794968.0, 11872264.0, 13177000.0, 14074100.0, 15184200.0, 16257249.0, 17481977.0, 18565243.0, 19546792.0, 20434176.0], "stack": "continent", "name": "Oceania"}], "title": {"text": ""}, "tooltip": {"axisPointer": {"type": ""}}, "yAxis": {}, "legend": {"data": ["Africa", "Americas", "Asia", "Europe", "Oceania"]}}
\ No newline at end of file
+{
+    "legend": {
+        "data": [
+            "Africa",
+            "Americas",
+            "Asia",
+            "Europe",
+            "Oceania"
+        ]
+    },
+    "xAxis": {
+        "data": [
+            1952,
+            1957,
+            1962,
+            1967,
+            1972,
+            1977,
+            1982,
+            1987,
+            1992,
+            1997,
+            2002,
+            2007
+        ]
+    },
+    "series": [
+        {
+            "name": "Africa",
+            "type": "bar",
+            "stack": "continent",
+            "data": [
+                9279525,
+                10270856,
+                11000948,
+                12760499,
+                14760787,
+                17152804,
+                20033753,
+                23254956,
+                26298373,
+                29072015,
+                31287142,
+                33333216
+            ]
+        },
+        {
+            "name": "Americas",
+            "type": "bar",
+            "stack": "continent",
+            "data": [
+                17876956,
+                19610538,
+                21283783,
+                22934225,
+                24779799,
+                26983828,
+                29341374,
+                31620918,
+                33958947,
+                36203463,
+                38331121,
+                40301927
+            ]
+        },
+        {
+            "name": "Asia",
+            "type": "bar",
+            "stack": "continent",
+            "data": [
+                8425333,
+                9240934,
+                10267083,
+                11537966,
+                13079460,
+                14880372,
+                12881816,
+                13867957,
+                16317921,
+                22227415,
+                25268405,
+                31889923
+            ]
+        },
+        {
+            "name": "Europe",
+            "type": "bar",
+            "stack": "continent",
+            "data": [
+                1282697,
+                1476505,
+                1728137,
+                1984060,
+                2263554,
+                2509048,
+                2780097,
+                3075321,
+                3326498,
+                3428038,
+                3508512,
+                3600523
+            ]
+        },
+        {
+            "name": "Oceania",
+            "type": "bar",
+            "label": {
+                "normal": {
+                    "show": true,
+                    "position": "top"
+                }
+            },
+            "stack": "continent",
+            "data": [
+                8691212,
+                9712569,
+                10794968,
+                11872264,
+                13177000,
+                14074100,
+                15184200,
+                16257249,
+                17481977,
+                18565243,
+                19546792,
+                20434176
+            ]
+        }
+    ],
+    "yAxis": {},
+    "tooltip": {
+        "axisPointer": {
+            "type": ""
+        }
+    },
+    "title": {
+        "text": ""
+    }
+}
\ No newline at end of file
diff --git a/krisk/tests/data/bar_ann_all.json b/krisk/tests/data/bar_ann_all.json
new file mode 100644
index 0000000..83dcc8d
--- /dev/null
+++ b/krisk/tests/data/bar_ann_all.json
@@ -0,0 +1,163 @@
+{
+    "legend": {
+        "data": [
+            "Africa",
+            "Americas",
+            "Asia",
+            "Europe",
+            "Oceania"
+        ]
+    },
+    "xAxis": {
+        "data": [
+            1952,
+            1957,
+            1962,
+            1967,
+            1972,
+            1977,
+            1982,
+            1987,
+            1992,
+            1997,
+            2002,
+            2007
+        ]
+    },
+    "series": [
+        {
+            "name": "Africa",
+            "type": "bar",
+            "label": {
+                "normal": {
+                    "show": true,
+                    "position": "inside"
+                }
+            },
+            "stack": "continent",
+            "data": [
+                9279525,
+                10270856,
+                11000948,
+                12760499,
+                14760787,
+                17152804,
+                20033753,
+                23254956,
+                26298373,
+                29072015,
+                31287142,
+                33333216
+            ]
+        },
+        {
+            "name": "Americas",
+            "type": "bar",
+            "label": {
+                "normal": {
+                    "show": true,
+                    "position": "inside"
+                }
+            },
+            "stack": "continent",
+            "data": [
+                17876956,
+                19610538,
+                21283783,
+                22934225,
+                24779799,
+                26983828,
+                29341374,
+                31620918,
+                33958947,
+                36203463,
+                38331121,
+                40301927
+            ]
+        },
+        {
+            "name": "Asia",
+            "type": "bar",
+            "label": {
+                "normal": {
+                    "show": true,
+                    "position": "inside"
+                }
+            },
+            "stack": "continent",
+            "data": [
+                8425333,
+                9240934,
+                10267083,
+                11537966,
+                13079460,
+                14880372,
+                12881816,
+                13867957,
+                16317921,
+                22227415,
+                25268405,
+                31889923
+            ]
+        },
+        {
+            "name": "Europe",
+            "type": "bar",
+            "label": {
+                "normal": {
+                    "show": true,
+                    "position": "inside"
+                }
+            },
+            "stack": "continent",
+            "data": [
+                1282697,
+                1476505,
+                1728137,
+                1984060,
+                2263554,
+                2509048,
+                2780097,
+                3075321,
+                3326498,
+                3428038,
+                3508512,
+                3600523
+            ]
+        },
+        {
+            "name": "Oceania",
+            "type": "bar",
+            "label": {
+                "normal": {
+                    "show": true,
+                    "position": "inside"
+                }
+            },
+            "stack": "continent",
+            "data": [
+                8691212,
+                9712569,
+                10794968,
+                11872264,
+                13177000,
+                14074100,
+                15184200,
+                16257249,
+                17481977,
+                18565243,
+                19546792,
+                20434176
+            ]
+        }
+    ],
+    "yAxis": {},
+    "tooltip": {
+        "axisPointer": {
+            "type": ""
+        }
+    },
+    "title": {
+        "text": ""
+    }
+}
\ No newline at end of file
diff --git a/krisk/tests/data/hist.json b/krisk/tests/data/hist.json
index 97fe107..5259b2d 100644
--- a/krisk/tests/data/hist.json
+++ b/krisk/tests/data/hist.json
@@ -1,1 +1,182 @@
-{"xAxis": {"data": [69, 69, 69, 69, 69, 69, 69, 69, 70, 70, 70, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71, 71, 71, 71, 72, 72, 72, 72, 72, 72, 72, 72, 72, 73, 73, 73, 73, 73, 73, 73, 73, 74, 74, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75, 75, 75, 75, 75, 76, 76, 76, 76, 76, 76, 76, 76, 76, 77, 77, 77, 77, 77, 77, 77, 77, 78, 78, 78, 78, 78, 78, 78, 78, 79, 79, 79, 79, 79, 79, 79, 79, 80, 80, 80, 80, 80, 80, 80, 80, 80, 81, 81]}, "series": [{"type": "bar", "data": [0.285, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.285, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.285, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.285, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.285, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.285, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.285, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.285, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.285, 0.0, 0.0, 0.0, 0.0, 0.285, 0.0, 0.0, 0.0, 0.0, 0.0, 0.285, 0.0, 0.0, 0.0, 0.285], "stack": "continent", "name": "Africa"}, {"type": "bar", "data": [0.649, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.649, 0.0, 0.0, 0.0, 0.0, 0.0, 0.649, 0.0, 0.0, 0.0, 0.649, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.649, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.649, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.649, 0.0, 0.0, 0.0, 0.0, 0.0, 0.649, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.649, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.649, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.649, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.649], "stack": "continent", "name": "Americas"}, {"type": "bar", "data": [0.555, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.555, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.555, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.555, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.555, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.555, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.555, 0.0, 0.0, 0.0, 0.0, 0.0, 0.555, 0.0, 0.0, 0.0, 0.0, 0.0, 0.555, 0.555, 0.0, 0.555, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.555], "stack": "continent", "name": "Asia"}, {"type": "bar", "data": [0.393, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.393, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.393, 0.0, 0.0, 0.0, 0.0, 0.0, 0.393, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.393, 0.0, 0.0, 0.0, 0.0, 0.0, 0.393, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.393, 0.0, 0.0, 0.0, 0.0, 0.0, 0.393, 0.0, 0.393, 0.0, 0.0, 0.0, 0.393, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.393, 0.0, 0.0, 0.393], "stack": "continent", "name": "Europe"}, {"type": "bar", "data": [0.688, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.688, 0.0, 0.0, 0.0, 0.0, 0.688, 0.0, 0.688, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.688, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.688, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.688, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.688, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.688, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.688, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.688, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.688], "stack": "continent", "name": "Oceania"}], "title": {"text": ""}, "tooltip": {"axisPointer": {"type": ""}}, "yAxis": {}, "legend": {"data": ["Africa", "Americas", "Asia", "Europe", "Oceania"]}}
\ No newline at end of file
+{
+    "legend": {
+        "data": [
+            "Africa",
+            "Americas",
+            "Asia",
+            "Europe",
+            "Oceania"
+        ]
+    },
+    "xAxis": {
+        "data": [
+            28,
+            31,
+            34,
+            36,
+            39,
+            41,
+            44,
+            47,
+            49,
+            52,
+            55,
+            57,
+            60,
+            62,
+            65,
+            68,
+            70,
+            73,
+            75,
+            78,
+            81
+        ]
+    },
+    "series": [
+        {
+            "name": "Africa",
+            "type": "bar",
+            "stack": "continent",
+            "data": [
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.083,
+                0.083,
+                0.083,
+                0.083,
+                0.083,
+                0.0,
+                0.083,
+                0.083,
+                0.0,
+                0.167,
+                0.083,
+                0.167,
+                0.0,
+                0.0,
+                0.0
+            ]
+        },
+        {
+            "name": "Americas",
+            "type": "bar",
+            "stack": "continent",
+            "data": [
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.083,
+                0.167,
+                0.167,
+                0.167,
+                0.25,
+                0.167,
+                0.0,
+                0.0
+            ]
+        },
+        {
+            "name": "Asia",
+            "type": "bar",
+            "stack": "continent",
+            "data": [
+                0.091,
+                0.182,
+                0.091,
+                0.091,
+                0.364,
+                0.182,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0
+            ]
+        },
+        {
+            "name": "Europe",
+            "type": "bar",
+            "stack": "continent",
+            "data": [
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.083,
+                0.083,
+                0.0,
+                0.083,
+                0.167,
+                0.167,
+                0.25,
+                0.083,
+                0.083,
+                0.0
+            ]
+        },
+        {
+            "name": "Oceania",
+            "type": "bar",
+            "stack": "continent",
+            "data": [
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.0,
+                0.167,
+                0.25,
+                0.167,
+                0.167,
+                0.25
+            ]
+        }
+    ],
+    "yAxis": {},
+    "tooltip": {
+        "axisPointer": {
+            "type": ""
+        }
+    },
+    "title": {
+        "text": ""
+    }
+}
\ No newline at end of file
diff --git a/krisk/tests/data/line.json b/krisk/tests/data/line.json
index e04d100..13a96b8 100644
--- a/krisk/tests/data/line.json
+++ b/krisk/tests/data/line.json
@@ -1,1 +1,178 @@
-{"xAxis": {"data": [1952, 1957, 1962, 1967, 1972, 1977, 1982, 1987, 1992, 1997, 2002, 2007]}, "series": [{"areaStyle": {"normal": {}}, "type": "line", "data": [43.077, 45.685, 48.303, 51.407, 54.518, 58.014, 61.368, 65.799, 67.744, 69.152, 70.994, 72.301], "stack": "continent", "name": "Africa"}, {"areaStyle": {"normal": {}}, "type": "line", "data": [62.485, 64.399, 65.142, 65.634, 67.065, 68.481, 69.942, 70.774, 71.868, 73.275, 74.34, 75.32], "stack": "continent", "name": "Americas"}, {"areaStyle": {"normal": {}}, "type": "line", "data": [28.801, 30.332, 31.997, 34.02, 36.088, 38.438, 39.854, 40.822, 41.674, 41.763, 42.129, 43.828], "stack": "continent", "name": "Asia"}, {"areaStyle": {"normal": {}}, "type": "line", "data": [55.23, 59.28, 64.82, 66.22, 67.69, 68.93, 70.42, 72.0, 71.581, 72.95, 75.651, 76.423], "stack": "continent", "name": "Europe"}, {"areaStyle": {"normal": {}}, "type": "line", "data": [69.12, 70.33, 70.93, 71.1, 71.93, 73.49, 74.74, 76.32, 77.56, 78.83, 80.37, 81.235], "stack": "continent", "name": "Oceania"}], "title": {"text": ""}, "tooltip": {"axisPointer": {"type": ""}}, "yAxis": {}, "legend": {"data": ["Africa", "Americas", "Asia", "Europe", "Oceania"]}}
\ No newline at end of file
+{
+    "legend": {
+        "data": [
+            "Africa",
+            "Americas",
+            "Asia",
+            "Europe",
+            "Oceania"
+        ]
+    },
+    "xAxis": {
+        "data": [
+            1952,
+            1957,
+            1962,
+            1967,
+            1972,
+            1977,
+            1982,
+            1987,
+            1992,
+            1997,
+            2002,
+            2007
+        ]
+    },
+    "series": [
+        {
+            "name": "Africa",
+            "label": {
+                "normal": {
+                    "show": true,
+                    "position": "top"
+                }
+            },
+            "type": "line",
+            "data": [
+                43.077,
+                45.685,
+                48.303,
+                51.407,
+                54.518,
+                58.014,
+                61.368,
+                65.799,
+                67.744,
+                69.152,
+                70.994,
+                72.301
+            ],
+            "areaStyle": {
+                "normal": {}
+            },
+            "stack": "continent"
+        },
+        {
+            "name": "Americas",
+            "label": {
+                "normal": {
+                    "show": true,
+                    "position": "top"
+                }
+            },
+            "type": "line",
+            "data": [
+                62.485,
+                64.399,
+                65.142,
+                65.634,
+                67.065,
+                68.481,
+                69.942,
+                70.774,
+                71.868,
+                73.275,
+                74.34,
+                75.32
+            ],
+            "areaStyle": {
+                "normal": {}
+            },
+            "stack": "continent"
+        },
+        {
+            "name": "Asia",
+            "label": {
+                "normal": {
+                    "show": true,
+                    "position": "top"
+                }
+            },
+            "type": "line",
+            "data": [
+                28.801,
+                30.332,
+                31.997,
+                34.02,
+                36.088,
+                38.438,
+                39.854,
+                40.822,
+                41.674,
+                41.763,
+                42.129,
+                43.828
+            ],
+            "areaStyle": {
+                "normal": {}
+            },
+            "stack": "continent"
+        },
+        {
+            "name": "Europe",
+            "label": {
+                "normal": {
+                    "show": true,
+                    "position": "top"
+                }
+            },
+            "type": "line",
+            "data": [
+                55.23,
+                59.28,
+                64.82,
+                66.22,
+                67.69,
+                68.93,
+                70.42,
+                72.0,
+                71.581,
+                72.95,
+                75.651,
+                76.423
+            ],
+            "areaStyle": {
+                "normal": {}
+            },
+            "stack": "continent"
+        },
+        {
+            "name": "Oceania",
+            "label": {
+                "normal": {
+                    "show": true,
+                    "position": "top"
+                }
+            },
+            "type": "line",
+            "data": [
+                69.12,
+                70.33,
+                70.93,
+                71.1,
+                71.93,
+                73.49,
+                74.74,
+                76.32,
+                77.56,
+                78.83,
+                80.37,
+                81.235
+            ],
+            "areaStyle": {
+                "normal": {}
+            },
+            "stack": "continent"
+        }
+    ],
+    "yAxis": {},
+    "tooltip": {
+        "axisPointer": {
+            "type": ""
+        }
+    },
+    "title": {
+        "text": ""
+    }
+}
\ No newline at end of file
diff --git a/krisk/tests/data/scatter.json b/krisk/tests/data/scatter.json
index ede290a..aa4d4ea 100644
--- a/krisk/tests/data/scatter.json
+++ b/krisk/tests/data/scatter.json
@@ -1,1 +1,116 @@
-{"xAxis": {"type": "value", "max": 69, "name": "lifeExp"}, "series": [{"type": "scatter", "data": [[43.077, 2449.008, 9279525.0, "Africa", "Algeria", 1952]], "name": "Africa"}, {"type": "scatter", "data": [[62.485, 5911.315, 17876956.0, "Americas", "Argentina", 1952]], "name": "Americas"}, {"type": "scatter", "data": [[28.801, 779.445, 8425333.0, "Asia", "Afghanistan", 1952]], "name": "Asia"}, {"type": "scatter", "data": [[55.23, 1601.056, 1282697.0, "Europe", "Albania", 1952]], "name": "Europe"}, {"type": "scatter", "data": [[69.12, 10039.596, 8691212.0, "Oceania", "Australia", 1952]], "name": "Oceania"}], "title": {"text": ""}, "tooltip": {"axisPointer": {"type": ""}}, "yAxis": {"type": "value", "max": 10039, "name": "gdpPercap"}, "visualMap": [{"min": 1282697.0, "dimension": 2, "precision": 0.1, "max": 17876956.0, "show": false, "inRange": {"symbolSize": [10, 70]}}], "legend": {"data": ["Africa", "Americas", "Asia", "Europe", "Oceania"]}}
\ No newline at end of file
+{
+    "legend": {
+        "data": [
+            "Africa",
+            "Americas",
+            "Asia",
+            "Europe",
+            "Oceania"
+        ]
+    },
+    "visualMap": [
+        {
+            "min": 1282697.0,
+            "show": false,
+            "precision": 0.1,
+            "max": 17876956.0,
+            "dimension": 2,
+            "inRange": {
+                "symbolSize": [
+                    10,
+                    70
+                ]
+            }
+        }
+    ],
+    "xAxis": {
+        "name": "lifeExp",
+        "max": 69,
+        "type": "value"
+    },
+    "series": [
+        {
+            "name": "Africa",
+            "type": "scatter",
+            "data": [
+                [
+                    43.077,
+                    2449.008,
+                    9279525.0,
+                    "Africa",
+                    "Algeria",
+                    1952
+                ]
+            ]
+        },
+        {
+            "name": "Americas",
+            "type": "scatter",
+            "data": [
+                [
+                    62.485,
+                    5911.315,
+                    17876956.0,
+                    "Americas",
+                    "Argentina",
+                    1952
+                ]
+            ]
+        },
+        {
+            "name": "Asia",
+            "type": "scatter",
+            "data": [
+                [
+                    28.801,
+                    779.445,
+                    8425333.0,
+                    "Asia",
+                    "Afghanistan",
+                    1952
+                ]
+            ]
+        },
+        {
+            "name": "Europe",
+            "type": "scatter",
+            "data": [
+                [
+                    55.23,
+                    1601.056,
+                    1282697.0,
+                    "Europe",
+                    "Albania",
+                    1952
+                ]
+            ]
+        },
+        {
+            "name": "Oceania",
+            "type": "scatter",
+            "data": [
+                [
+                    69.12,
+                    10039.596,
+                    8691212.0,
+                    "Oceania",
+                    "Australia",
+                    1952
+                ]
+            ]
+        }
+    ],
+    "yAxis": {
+        "name": "gdpPercap",
+        "max": 10039,
+        "type": "value"
+    },
+    "tooltip": {
+        "axisPointer": {
+            "type": ""
+        }
+    },
+    "title": {
+        "text": ""
+    }
+}
\ No newline at end of file
diff --git a/krisk/tests/data/scatter_single.json b/krisk/tests/data/scatter_single.json
new file mode 100644
index 0000000..641fa20
--- /dev/null
+++ b/krisk/tests/data/scatter_single.json
@@ -0,0 +1,86 @@
+{
+    "legend": {
+        "data": []
+    },
+    "visualMap": [
+        {
+            "min": 1282697.0,
+            "show": false,
+            "precision": 0.1,
+            "max": 17876956.0,
+            "dimension": 2,
+            "inRange": {
+                "symbolSize": [
+                    10,
+                    70
+                ]
+            }
+        }
+    ],
+    "xAxis": {
+        "name": "lifeExp",
+        "max": 69,
+        "type": "value"
+    },
+    "series": [
+        {
+            "name": "lifeExp",
+            "type": "scatter",
+            "data": [
+                [
+                    43.077,
+                    2449.008,
+                    9279525.0,
+                    "Africa",
+                    "Algeria",
+                    1952
+                ],
+                [
+                    62.485,
+                    5911.315,
+                    17876956.0,
+                    "Americas",
+                    "Argentina",
+                    1952
+                ],
+                [
+                    28.801,
+                    779.445,
+                    8425333.0,
+                    "Asia",
+                    "Afghanistan",
+                    1952
+                ],
+                [
+                    55.23,
+                    1601.056,
+                    1282697.0,
+                    "Europe",
+                    "Albania",
+                    1952
+                ],
+                [
+                    69.12,
+                    10039.596,
+                    8691212.0,
+                    "Oceania",
+                    "Australia",
+                    1952
+                ]
+            ]
+        }
+    ],
+    "yAxis": {
+        "name": "gdpPercap",
+        "max": 10039,
+        "type": "value"
+    },
+    "tooltip": {
+        "axisPointer": {
+            "type": ""
+        }
+    },
+    "title": {
+        "text": ""
+    }
+}
\ No newline at end of file
diff --git a/krisk/tests/test_chart.py b/krisk/tests/test_chart.py
index b985f7c..73709f8 100644
--- a/krisk/tests/test_chart.py
+++ b/krisk/tests/test_chart.py
@@ -1,15 +1,18 @@
 
 import krisk.plot as kk
 
+def test_replot_and_resync(bar_simple,df_simple):
+    
+    c = bar_simple
+    stripped = lambda x: x.data.replace('\n', '').replace(' ','')
+    assert stripped(c.replot(c)) == stripped(c.resync_data(df_simple))
+    
+    
 def test_flip(bar_simple):
     
     assert bar_simple.get_option()['xAxis'] == bar_simple.flip_axes().get_option()['yAxis']
+ 
     
-def test_color(bar_simple):
-    
-    colored = bar_simple.set_color(background='green',palette=['purple']).get_option()
-    assert colored['backgroundColor'] == 'green'
-    assert colored['color'] == ['purple']
     
 def test_read_df(gapminder):
     
@@ -33,4 +36,12 @@ def test_on_event(df_simple):
     assert on_event._events == {'click': 'handler_foo'}
     code_handler = on_event._repr_javascript_().split('\n')[-13]
     input_code = '    var code_input = "import json; handler_foo(json.loads(\'" + json_strings + "\'))";'
-    assert  code_handler == input_code
\ No newline at end of file
+    assert  code_handler == input_code
+    
+       
+def test_color(bar_simple):
+    
+    # Set color modify the bar_simple itself! Potentially bug
+    colored = bar_simple.set_color(background='green',palette=['purple']).get_option()
+    assert colored['backgroundColor'] == 'green'
+    assert colored['color'] == ['purple']
\ No newline at end of file
diff --git a/krisk/tests/test_plot.py b/krisk/tests/test_plot.py
index 77e1ebd..97e2a87 100644
--- a/krisk/tests/test_plot.py
+++ b/krisk/tests/test_plot.py
@@ -4,36 +4,43 @@ import pytest
 import krisk.plot as kk
 DATA_DIR = 'krisk/tests/data'
 
-@pytest.fixture
-def df():
-    import pandas as pd
-    return (pd.read_csv(DATA_DIR+'/gapminderDataFiveYear.txt',sep='\t')
-          .groupby(['year','continent'],as_index=False).first())
-
-def test_bar(df):
+def test_bar(gapminder):
 
+    #Bar
     true_option = json.load(open(DATA_DIR+'/bar.json','r'))
-    p = kk.bar(df,'lifeExp',y='pop',category='continent',how='mean',stacked=True)
-
-    assert p._option == true_option
+    p = kk.bar(gapminder,'year',y='pop',category='continent',how='mean',stacked=True, annotate=True)
+    assert p.get_option() == true_option
+    
+    # Bar Annotate All
+    true_option = json.load(open(DATA_DIR+'/bar_ann_all.json','r'))
+    p = kk.bar(gapminder,'year',y='pop',category='continent',how='mean',stacked=True, annotate='all')
+    assert p.get_option() == true_option
 
-def test_line(df):
+def test_line(gapminder):
     
     true_option = json.load(open(DATA_DIR+'/line.json','r'))
-    p = kk.line(df,'year',y='lifeExp',category='continent',how='mean',stacked=True,area=True)
+    p = kk.line(gapminder,'year',y='lifeExp',category='continent',how='mean',
+                stacked=True,area=True,annotate='all')
     
-    assert p._option == true_option
+    assert p.get_option() == true_option
     
-def test_hist(df):
+def test_hist(gapminder):
     
     true_option = json.load(open(DATA_DIR+'/hist.json','r'))
-    p = kk.hist(df,'lifeExp',category='continent',bins=100,normed=True,stacked=True)
+    p = kk.hist(gapminder,'lifeExp',category='continent',bins=20,normed=True,stacked=True)
     
-    assert p._option == true_option
+    assert p.get_option() == true_option
     
-def test_scatter(df):
+def test_scatter(gapminder):
     
+    # Grouped Scatter
     true_option = json.load(open(DATA_DIR+'/scatter.json','r'))
-    p = kk.scatter(df[df.year == 1952],'lifeExp','gdpPercap',size='pop',category='continent')
+    p = kk.scatter(gapminder[gapminder.year == 1952],'lifeExp','gdpPercap',size='pop',category='continent')
+    assert p.get_option() == true_option
+    
+    # Scatter
+    true_option = json.load(open(DATA_DIR+'/scatter_single.json','r'))
+    p = kk.scatter(gapminder[gapminder.year == 1952],'lifeExp','gdpPercap',size='pop')
+    assert p.get_option() == true_option
     
-    assert p._option == true_option
\ No newline at end of file
+    
\ No newline at end of file