In [1]:
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
import matplotlib.pyplot as plt
import csv
from bokeh.plotting import figure, show
from bokeh.io import output_notebook
In [2]:
with open('../data/twitter_stars.csv', 'r', encoding="utf-8") as csvfile:
reader = csv.reader(csvfile)
columns = list(zip(*reader))
stars = {c[0] : c[1:] for c in columns}
for key in stars.keys():
stars[key] = [int(n) for n in stars[key]]
likes = [favs + rts for favs, rts in zip(stars['favs'], stars['rts'])]
print(likes)
In [3]:
hist_data = np.histogram(likes, bins = 30)
binsize = hist_data[1][1] - hist_data[1][0]
In [12]:
hist_data[1][-1]
Out[12]:
In [13]:
trace = go.Histogram(
x=likes,
autobinx=False,
xbins=dict(
start=hist_data[1][0],
end=hist_data[1][-1]+1,
size=binsize
)
)
In [14]:
data = [trace]
In [15]:
layout = go.Layout(
bargroupgap=0.01
)
In [16]:
fig = go.Figure(data=data, layout=layout)
In [17]:
py.iplot(fig)
Out[17]:
In [9]:
plt.hist(likes, bins=30)
plt.show()
In [10]:
output_notebook()
In [11]:
hist, edges = np.histogram(likes, bins = 30)
plot = figure(plot_height=400, plot_width=400, title="histogram of @python_tip stars",
tools="crosshair,pan,reset,save,wheel_zoom,hover")
hh = plot.quad(bottom=0, left=edges[:-1], right=edges[1:], top=hist, fill_color="#446785", line_color="#033649")
show(plot)
In [ ]: