In this screen we represent the bans on a timeline.

  1. we need total number of bans
  2. date stamps they happened
  3. sector wise ( use variations in this one)

Link to the destination

Graphs we are to use in this one

Dot chart


In [3]:
""" 
Example from the main website gallery

http://bokeh.pydata.org/en/latest/docs/gallery/dot_chart.html

"""

#######

from bokeh.plotting import hplot, vplot, gridplot

#######
from collections import OrderedDict

from bokeh._legacy_charts import Dot, show, output_file

# create some example data
xyvalues = OrderedDict(
    python=[2, 3, 7, 5, 26],
    pypy=[12, 33, 47, 15, 126],
    jython=[22, 43, 10, 25, 26],
)

# any of the following commented are also valid Dot inputs
#xyvalues = pd.DataFrame(xyvalues)
#xyvalues = list(xyvalues.values())
#xyvalues = np.array(list(xyvalues.values()))

output_file("all_combined_output.html")


TOOLS="resize,crosshair,pan,wheel_zoom,box_zoom,reset,previewsave"

dots = Dot(
    xyvalues, cat=['lists','loops','dicts', 'gen exp', 'exceptions'], 
    title="Dots Example", ylabel='Performance', legend=True
)

show(dots)


C:\Anaconda3\lib\site-packages\bokeh\_legacy_charts\_chart.py:92: UserWarning: Instantiating a Legacy Chart from bokeh._legacy_charts
  warn("Instantiating a Legacy Chart from bokeh._legacy_charts")

Heatmap


In [5]:
""" 
Example from the main website gallery

http://bokeh.pydata.org/en/latest/docs/gallery/cat_heatmap_chart.html

"""


from bokeh._legacy_charts import HeatMap, output_file, show
from bokeh.palettes import YlOrRd9 as palette
from bokeh.sampledata.unemployment1948 import data

# pandas magic
df = data[data.columns[:-1]]
df2 = df.set_index(df[df.columns[0]].astype(str))
df2.drop(df.columns[0], axis=1, inplace=True)
df3 = df2.transpose()

#output_file("cat_heatmap.html")


palette = palette[::-1]  # Reverse the color order so dark red is highest unemployment




hm = HeatMap(df3, title="categorical heatmap", width=800, palette=palette)

#show(hm)

show(hplot(hm, dots))


C:\Anaconda3\lib\site-packages\bokeh\_legacy_charts\_chart.py:92: UserWarning: Instantiating a Legacy Chart from bokeh._legacy_charts
  warn("Instantiating a Legacy Chart from bokeh._legacy_charts")

Scatter Chart


In [12]:
"""
Example from the main website gallery

http://bokeh.pydata.org/en/latest/docs/gallery/iris_scatter_chart.html

"""

from collections import OrderedDict

from bokeh._legacy_charts import Scatter, output_file, show
from bokeh.sampledata.iris import flowers

# fill a data frame with the data of interest and create a groupby object
df = flowers[["petal_length", "petal_width", "species"]]
xyvalues = g = df.groupby("species")

# drop that groupby object into a dict
pdict = OrderedDict()

for i in g.groups.keys():
    labels = g.get_group(i).columns
    xname = labels[0]
    yname = labels[1]
    x = getattr(g.get_group(i), xname)
    y = getattr(g.get_group(i), yname)
    pdict[i] = zip(x, y)

# any of the following commented are also valid Scatter inputs
#xyvalues = pdict
#xyvalues = pd.DataFrame(xyvalues)
#xyvalues = xyvalues.values()
#xyvalues = np.array(xyvalues.values())

#output_file("iris_scatter.html")



scatter = Scatter(xyvalues, ylabel='petal_width')

show(scatter)


C:\Anaconda3\lib\site-packages\bokeh\_legacy_charts\_chart.py:92: UserWarning: Instantiating a Legacy Chart from bokeh._legacy_charts
  warn("Instantiating a Legacy Chart from bokeh._legacy_charts")

In [2]:
from collections import OrderedDict

import pandas as pd

from bokeh.charts import Donut, show, output_file
from bokeh.sampledata.olympics2014 import data

# throw the data into a pandas data frame
df = pd.io.json.json_normalize(data['data'])

# filter by countries with at least one medal and sort
df = df[df['medals.total'] > 8]
df = df.sort("medals.total", ascending=False)

# get the countries and we group the data by medal type
countries = df.abbr.values.tolist()
gold = df['medals.gold'].astype(float).values
silver = df['medals.silver'].astype(float).values
bronze = df['medals.bronze'].astype(float).values

# build a dict containing the grouped data
medals = OrderedDict()
medals['bronze'] = bronze
medals['silver'] = silver
medals['gold'] = gold

# any of the following commented are also valid Donut inputs
#medals = list(medals.values())
#medals = np.array(list(medals.values()))
#medals = pd.DataFrame(medals)

output_file("donut.html")

donut = Donut(medals, countries)

show(donut)

In [13]:
from collections import OrderedDict

import pandas as pd

from bokeh.charts import Bar, output_file, show
from bokeh.sampledata.olympics2014 import data

df = pd.io.json.json_normalize(data['data'])

# filter by countries with at least one medal and sort
df = df[df['medals.total'] > 0]
df = df.sort("medals.total", ascending=False)

# get the countries and we group the data by medal type
countries = df.abbr.values.tolist()
gold = df['medals.gold'].astype(float).values
silver = df['medals.silver'].astype(float).values
bronze = df['medals.bronze'].astype(float).values

# build a dict containing the grouped data
medals = OrderedDict(bronze=bronze, silver=silver, gold=gold)

# any of the following commented are also alid Bar inputs
#medals = pd.DataFrame(medals)
#medals = list(medals.values())

output_file("stacked_bar.html")

bar = Bar(medals, countries, title="Stacked bars", stacked=True)

show(bar)


C:\Anaconda3\lib\site-packages\IPython\kernel\__main__.py:12: FutureWarning: sort(columns=....) is deprecated, use sort_values(by=.....)
---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
<ipython-input-13-2de3936cc447> in <module>()
     27 output_file("stacked_bar.html")
     28 
---> 29 bar = Bar(medals, countries, title="Stacked bars", stacked=True)
     30 
     31 show(bar)

C:\Anaconda3\lib\site-packages\bokeh\charts\builder\bar_builder.py in Bar(data, label, values, color, stack, group, agg, xscale, yscale, xgrid, ygrid, continuous_range, **kw)
     97     kw['y_range'] = y_range
     98 
---> 99     return create_and_build(BarBuilder, data, **kw)
    100 
    101 

C:\Anaconda3\lib\site-packages\bokeh\charts\_builder.py in create_and_build(builder_class, *data, **kws)
     57     # create the new builder
     58     builder_kws = {k: v for k, v in kws.items() if k in builder_props}
---> 59     builder = builder_class(*data, **builder_kws)
     60 
     61     # create a chart to return, since there isn't one already

C:\Anaconda3\lib\site-packages\bokeh\charts\_builder.py in __init__(self, *args, **kws)
    174 
    175             # handle input attrs and ensure attrs have access to data
--> 176             self._setup_attrs(data, kws)
    177 
    178         super(Builder, self).__init__(**kws)

C:\Anaconda3\lib\site-packages\bokeh\charts\_builder.py in _setup_attrs(self, data, kws)
    205             elif isinstance(attr, str) or isinstance(attr, list):
    206                 self.attributes[attr_name] = self.default_attributes[attr_name].clone()
--> 207                 self.attributes[attr_name].setup(data=source, columns=attr)
    208 
    209             else:

C:\Anaconda3\lib\site-packages\bokeh\charts\_attributes.py in setup(self, data, columns)
    107 
    108             if columns is not None:
--> 109                 self.set_columns(columns)
    110 
    111         if self.columns is not None and self.data is not None:

C:\Anaconda3\lib\site-packages\bokeh\charts\_attributes.py in set_columns(self, columns)
    100             # assume this is now the iterable at this point
    101             self.iterable = columns
--> 102             self._setup_default()
    103 
    104     def setup(self, data=None, columns=None):

C:\Anaconda3\lib\site-packages\bokeh\charts\_attributes.py in _setup_default(self)
     68 
     69     def _setup_default(self):
---> 70         self.default = next(self._setup_iterable())
     71 
     72     def _setup_iterable(self):

StopIteration: 

In [ ]: