# -*- coding: utf-8 -*-
"""
Created on Wed Mar 27 09:27:31 2019

@author: user
"""

#conda install -c conda-forge pywaffle 
#! pip install pywaffle
# Reference: https://stackoverflow.com/questions/41400136/how-to-do-waffle-charts-in-python-square-piechart
from pywaffle import Waffle

# Import
df_raw = pd.read_csv("https://github.com/selva86/datasets/raw/master/mpg_ggplot2.csv")

# Prepare Data
df = df_raw.groupby('class').size().reset_index(name='counts')
n_categories = df.shape[0]
colors = [plt.cm.inferno_r(i/float(n_categories)) for i in range(n_categories)]

# Draw Plot and Decorate
fig = plt.figure(
    FigureClass=Waffle,
    plots={
        '111': {
            'values': df['counts'],
            'labels': ["{0} ({1})".format(n[0], n[1]) for n in df[['class', 'counts']].itertuples()],
            'legend': {'loc': 'upper left', 'bbox_to_anchor': (1.05, 1), 'fontsize': 12},
            'title': {'label': '# Vehicles by Class', 'loc': 'center', 'fontsize':18}
        },
    },
    rows=7,
    colors=colors,
    figsize=(16, 9)
)
f2eb15ea9ae126b73ae56b99bddf3172cda63c48
<mask token>

<mask token>
df_raw = pd.read_csv(
    'https://github.com/selva86/datasets/raw/master/mpg_ggplot2.csv')
df = df_raw.groupby('class').size().reset_index(name='counts')
n_categories = df.shape[0]
colors = [plt.cm.inferno_r(i / float(n_categories)) for i in range(
    n_categories)]
fig = plt.figure(FigureClass=Waffle, plots={'111': {'values': df['counts'],
    'labels': ['{0} ({1})'.format(n[0], n[1]) for n in df[['class',
    'counts']].itertuples()], 'legend': {'loc': 'upper left',
    'bbox_to_anchor': (1.05, 1), 'fontsize': 12}, 'title': {'label':
    '# Vehicles by Class', 'loc': 'center', 'fontsize': 18}}}, rows=7,
    colors=colors, figsize=(16, 9))

<mask token>
from pywaffle import Waffle
df_raw = pd.read_csv(
    'https://github.com/selva86/datasets/raw/master/mpg_ggplot2.csv')
df = df_raw.groupby('class').size().reset_index(name='counts')
n_categories = df.shape[0]
colors = [plt.cm.inferno_r(i / float(n_categories)) for i in range(
    n_categories)]
fig = plt.figure(FigureClass=Waffle, plots={'111': {'values': df['counts'],
    'labels': ['{0} ({1})'.format(n[0], n[1]) for n in df[['class',
    'counts']].itertuples()], 'legend': {'loc': 'upper left',
    'bbox_to_anchor': (1.05, 1), 'fontsize': 12}, 'title': {'label':
    '# Vehicles by Class', 'loc': 'center', 'fontsize': 18}}}, rows=7,
    colors=colors, figsize=(16, 9))

# -*- coding: utf-8 -*-
"""
Created on Wed Mar 27 09:27:31 2019

@author: user
"""

#conda install -c conda-forge pywaffle 
#! pip install pywaffle
# Reference: https://stackoverflow.com/questions/41400136/how-to-do-waffle-charts-in-python-square-piechart
from pywaffle import Waffle

# Import
df_raw = pd.read_csv("https://github.com/selva86/datasets/raw/master/mpg_ggplot2.csv")

# Prepare Data
df = df_raw.groupby('class').size().reset_index(name='counts')
n_categories = df.shape[0]
colors = [plt.cm.inferno_r(i/float(n_categories)) for i in range(n_categories)]

# Draw Plot and Decorate
fig = plt.figure(
    FigureClass=Waffle,
    plots={
        '111': {
            'values': df['counts'],
            'labels': ["{0} ({1})".format(n[0], n[1]) for n in df[['class', 'counts']].itertuples()],
            'legend': {'loc': 'upper left', 'bbox_to_anchor': (1.05, 1), 'fontsize': 12},
            'title': {'label': '# Vehicles by Class', 'loc': 'center', 'fontsize':18}
        },
    },
    rows=7,
    colors=colors,
    figsize=(16, 9)
)