In [1]:
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
df = pd.read_csv("mn-budget-detail-2014.csv")
df = df.sort_values('amount', ascending=False)
df.head()
Out[2]:
In [4]:
sizes = df.groupby('category').size()
sizes.plot(kind='barh', figsize=(15,10))
Out[4]:
In [5]:
import seaborn as sns
sns.set_style('white')
In [6]:
sizes.plot(kind='bar', figsize=(15,10))
Out[6]:
In [10]:
sns.set_context('poster')
bar_plot = sns.barplot(x=sizes.index.values, y=sizes.values, palette="BuGn_r", order=sizes.index.values.tolist())
plt.xticks(rotation=90)
Out[10]:
In [11]:
from ggplot import *
In [12]:
# dfs = sizes.to_frame(name='count').reset_index()
# dfs['count'] = dfs['count'].astype(float)
# print(dfs.columns)
# print(dfs.index)
# print(dfs.head())
# print(dfs['category'].tolist())
# print(dfs['count'])
dfs = df.sort_values('amount',ascending=False)[:10]
p = ggplot(dfs, aes(x="category",y="amount")) + \
geom_bar(stat="bar", labels=dfs["category"].tolist()) +\
ggtitle("MN Capital Budget - 2014") + \
xlab("Categories") + \
ylab("Coutns") + scale_y_continuous(labels='millions') + \
theme(axis_text_x=element_text(angle=90))
print p
In [13]:
from bokeh.charts import Bar, show
In [14]:
bar = Bar(sizes, filename="bar.html", title="MN Capital Budget - 2014", legend=False)
show(bar)
In [15]:
import pygal
from pygal.style import LightStyle
In [16]:
bar_chart = pygal.Bar(style=LightStyle, width=800, height=600,
legend_at_bottom=True, human_readable=True,
title='MN Capital Budget - 2014')
In [17]:
for index, row in sizes.iteritems():
bar_chart.add(index, row)
In [18]:
# bar_chart.render_to_file('budget.svg')
# bar_chart.render_to_png('budget.png')
bar_chart.render_in_browser()
In [19]:
import plotly.plotly as py
from plotly.graph_objs import *
In [20]:
data = Data([
Bar(
x=sizes.index,
y=sizes.values
)
])
In [21]:
layout = Layout(
title='2014 MN Capital Budget',
font=Font(
family='Raleway, sans-serif'
),
showlegend=False,
xaxis=XAxis(
tickangle=-45
),
bargap=0.05
)
fig = Figure(data=data, layout=layout)
plot_url = py.plot(data,filename='MN Capital Budget - 2014')
py.image.save_as(fig, 'mn-14-budget.png')
In [ ]: