In [1]:
import wget
import os
import zipfile
import urllib3
import certifi
import sys
import glob
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import plotly.offline as py
import plotly.graph_objs as go
import plotly.tools as tls
import seaborn as sns
import plotly
plotly.offline.init_notebook_mode()
In [2]:
df = pd.read_csv("italy_earthquakes_from_2016-08-24_to_2016-11-30.csv").set_index('Time')
df.index = pd.to_datetime(df.index)
df.head()
Out[2]:
In [3]:
trace = go.Scatter(x=df.index,
y=df.Magnitude)
data = [trace]
layout = dict(
title='Time series for Magnitude',
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=1,
label='1m',
step='month',
stepmode='backward'),
dict(step='all')
])
),
rangeslider=dict(),
type='date'
)
)
fig = dict(data=data, layout=layout)
py.iplot(fig)
In [4]:
trace = go.Scattergl(
x = df.index,
y = df.Magnitude,
mode = 'markers',
marker = dict(
color = 'FFBAD2',
line = dict(width = 1)
)
)
data = [trace]
layout = go.Layout(
title='Magnitude <br>(Hover to see the magnitude of the eartquake and the time it occured)',
xaxis=dict(
title='Time',
titlefont=dict(
family='Courier New, monospace',
size=18,
color='#7f7f7f'
)
),
yaxis=dict(
title='Magnitude',
titlefont=dict(
family='Courier New, monospace',
size=18,
color='#7f7f7f'
)
)
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='compare_webgl')
In [5]:
import vincent
vincent.initialize_notebook()
line = vincent.Line(df[['Magnitude', 'Depth/Km']])
line.axis_titles(x='Date', y='Value')
line.legend(title='Magnitude vs Depth/Km')
Out[5]:
In [31]:
import bokeh
from bokeh.io import output_notebook
In [36]:
from bokeh.models import BoxAnnotation
from bokeh.plotting import figure, show, output_file
TOOLS = "pan,wheel_zoom,box_zoom,reset,save"
# reduce data size
p = figure(x_axis_type="datetime", tools=TOOLS, title="Earthquake's Magnitude")
p.xgrid.grid_line_color=None
p.ygrid.grid_line_alpha=0.5
p.xaxis.axis_label = 'Time (2016)'
p.yaxis.axis_label = 'Magnitude'
p.line(df.index, df.Magnitude, line_color="gray")
p.add_layout(BoxAnnotation(top=80, fill_alpha=0.1, fill_color='red'))
p.add_layout(BoxAnnotation(bottom=80, top=180, fill_alpha=0.1, line_color='olive', fill_color='olive'))
p.add_layout(BoxAnnotation(bottom=180, fill_alpha=0.1, fill_color='red'))
#output_file("box_annotation.html", title="box_annotation.py example")
output_notebook()
show(p)
In [ ]: