from plotly.offline import download_plotlyjs, init_notebook_mode, iplot, plot
init_notebook_mode(connected=True)
import pandas as pd
import datetime
df=pd.read_excel('Mining-BTC-180.xls')
df.head()
Date | Number-transactions | Output-volume(BTC) | Market-price | Hash-rate | Cost-per-trans-USD | Mining-revenue-USD | Transaction-fees-BTC | |
---|---|---|---|---|---|---|---|---|
0 | 2017-04-29 00:00:00 | 341319 | 4.488916e+06 | 3.119179e+06 | 4.488916e+06 | 9.460796 | 3.119179e+06 | 256.376481 |
1 | 2017-04-30 00:00:00 | 281489 | 3.918072e+06 | 2.720216e+06 | 3.918072e+06 | 10.030446 | 2.720216e+06 | 199.307639 |
2 | 2017-05-01 00:00:00 | 294786 | 3.892124e+06 | 2.878278e+06 | 3.892124e+06 | 10.108888 | 2.878278e+06 | 227.748866 |
3 | 2017-05-02 00:00:00 | 333161 | 4.099704e+06 | 3.149553e+06 | 4.099704e+06 | 9.796472 | 3.149553e+06 | 272.679662 |
4 | 2017-05-03 00:00:00 | 295149 | 3.425069e+06 | 2.760373e+06 | 3.425069e+06 | 9.691347 | 2.760373e+06 | 247.343677 |
df.columns
Index([u'Date', u'Number-transactions', u'Output-volume(BTC)', u'Market-price', u'Hash-rate', u'Cost-per-trans-USD', u'Mining-revenue-USD', u'Transaction-fees-BTC'], dtype='object')
Convert each string in df['Date']
to a datetime.date element.
df['Date']=map(lambda x: x.date(),[pd.to_datetime(dr) for dr in df['Date']])
df.columns
Index([u'Date', u'Number-transactions', u'Output-volume(BTC)', u'Market-price', u'Hash-rate', u'Cost-per-trans-USD', u'Mining-revenue-USD', u'Transaction-fees-BTC'], dtype='object')
table_trace1=dict(type = 'table',
domain=dict(x= [0.0, 0.5],
y= [0, 1.0]),
columnwidth= [30]+[ 33, 35, 33],
columnorder=[0, 1, 2, 3, 4],
header = dict(height = 50,
values = [['<b>Date</b>'],['<b>Hash Rate, TH/sec</b>'],
['<b>Mining revenue</b>'], ['<b>Transaction fees</b>']],
line = dict(color='rgb(50,50,50)'),
align = ['left']*5,
font = dict(color=['rgb(45,45,45)']*5, size=14),
fill = dict( color = '#d562be' )#fill color for header
),
cells = dict(values = [df['Date'][-20:], df['Hash-rate'][-20:], df['Mining-revenue-USD'][-20:],
df['Transaction-fees-BTC'][-20:],
],
line = dict(color='#506784'),
align = ['left']*5,
font = dict(color=['rgb(40,40,40)']*5, size=12),
format = [None]+ [",.2f"]*2+[',.4f'],
prefix = [None]*2+['$', u'\u20BF'],
suffix=[None]*4,
height = 27,
fill = dict( color = ['rgb(235,193, 238', 'rgba(228, 222,249, 0.65)'] )
)
)
trace1=dict(type='scatter',
x=df['Date'],
y=df['Hash-rate'],
xaxis='x1',
yaxis='y1',
mode='lines',
line=dict(width=2, color='#9748a1'),
name='hash-rate-TH/s')
trace2=dict(type='scatter',
x=df['Date'],
y=df['Mining-revenue-USD'],
xaxis='x2',
yaxis='y2',
mode='lines',
line=dict(width=2, color='#b04553'),
name='mining revenue')
trace3=dict(type='scatter',
x=df['Date'],
y=df['Transaction-fees-BTC'],
xaxis='x3',
yaxis='y3',
mode='lines',
line=dict(width=2, color='#af7bbd'),
name='transact-fee')
axis=dict(showline=True, zeroline=False, showgrid=True, mirror=True,
ticklen=4, gridcolor='#ffffff', tickfont=dict(size=10))
layout1 = dict(width=950, height=800, autosize=False, title='Bitcoin mining stats for 180 days',
margin = dict(t=100,l=0,r=0,b=100),
showlegend=False,
xaxis1=dict(axis, **dict(domain=[0.55,0.98], anchor= 'y1', showticklabels=False)),
xaxis2=dict(axis, **dict(domain=[0.55,0.98], anchor= 'y2', showticklabels=False)),
xaxis3=dict(axis, **dict(domain=[0.55,0.98], anchor= 'y3')),
yaxis1=dict(axis, **dict(domain=[0.68,1], anchor= 'x1', hoverformat='.2f')),
yaxis2=dict(axis, **dict(domain=[0.34,0.66], anchor= 'x2', tickprefix='$', hoverformat='.2f')),
yaxis3=dict(axis, **dict(domain=[0.0,0.32], anchor= 'x3', tickprefix=u'\u20BF', hoverformat='.2f')),
plot_bgcolor='rgba(228, 222,249, 0.65)' ,
annotations=[dict(showarrow=False,
text='The last 20 records',
xref='paper',
yref='paper',
x=0.2,
y=1.01,
xanchor='left',
yanchor='bottom',
font=dict(
size=15 ))]
)
fig1 = dict(data=[table_trace1, trace1, trace2, trace3], layout=layout1)
iplot(fig1)
df.columns
Index([u'Date', u'Number-transactions', u'Output-volume(BTC)', u'Market-price', u'Hash-rate', u'Cost-per-trans-USD', u'Mining-revenue-USD', u'Transaction-fees-BTC'], dtype='object')
table_trace2=dict(type = 'table',
domain=dict(x= [0.1, 0.9],
y= [0.4, 1]),
columnwidth= [30]+[ 33, 35, 33],
columnorder=[0, 1, 2, 3, 4],
header = dict(height = 50,
values = [['<b>Date</b>'],['<b>Nr-transactions</b>'],
['<b>Output-volume</b>'],
['<b>Cost-per-trans</b>']],
line = dict(color='rgb(50,50,50)'),
align = ['left']*4,
font = dict(color=['rgb(45,45,45)']*4, size=14),
fill = dict( color = '#d562be' )#fill color for header
),
cells = dict(values = [df['Date'][-60:-44],
df['Number-transactions'][-60:-44],
df['Output-volume(BTC)'][-60:-44],
df['Cost-per-trans-USD'][-60:-44]
],
line = dict(color='#506784'),
align = ['left']*4,
font = dict(color=['rgb(40,40,40)']*4, size=12),
format = [None]+ ['d']+[",.2f"]*2,
prefix = [None]*2+[ u'\u20BF', '$'],
suffix=[None]*4,
height = 27,
fill = dict( color = ['rgb(235,193, 238', 'rgba(228, 222,249, 0.65)'] )
)
)
trace4=dict(type='scatter',
x=df['Date'],
y=df['Number-transactions'],
xaxis='x1',
yaxis='y1',
mode='lines',
line=dict(width=2, color='#af7bbd'),
name='nr-transac')
trace5=dict(type='scatter',
x=df['Date'],
y=df['Output-volume(BTC)'],
xaxis='x2',
yaxis='y2',
mode='lines',
line=dict(width=2, color='#b04553'),
name='ouput-vol')
trace6=dict(type='scatter',
x=df['Date'],
y= df['Cost-per-trans-USD'],
xaxis='x3',
yaxis='y3',
mode='lines',
line=dict(width=2, color='#9748a1'),
name='cost-transac')
layout2 = dict(width=800, height=1000, autosize=False, title='Bitcoin transaction summary for 180 days',
margin = dict(t=100, l=60,r=0),
showlegend=False,
xaxis1=dict(axis, **dict(domain=[0.1,0.9], anchor= 'y1', showgrid=False, showticklabels=False)),
xaxis2=dict(axis, **dict(domain=[0.1,0.9], anchor= 'y2', showgrid=False, showticklabels=False)),
xaxis3=dict(axis, **dict(domain=[0.1,0.9], anchor= 'y3',showgrid=False, showticklabels=True)),
yaxis1=dict(axis, **dict(domain=[0.28, 0.398], anchor= 'x1', showgrid=False, hoverformat='d')),
yaxis2=dict(axis, **dict(domain=[0.14, 0.26], anchor= 'x2', showgrid=False, tickprefix= u'\u20BF', hoverformat='.2f')),
yaxis3=dict(axis, **dict(domain=[0, 0.12], anchor= 'x3', showgrid=False, tickprefix='S', hoverformat='.2f')),
plot_bgcolor='rgba(228, 222,249, 0.65)',
annotations=[dict(showarrow=False,
text='16 records around the date of september 3, 2017',
xref='paper',
yref='paper',
x=0.2,
y=1.01,
xanchor='left',
yanchor='bottom',
font=dict(
size=15 ))],
shapes=[dict(type='rect',
xref='x3',
yref='y3',
x0=df['Date'].iloc[-60],
y0=8,
x1=df['Date'].iloc[-43],
y1=53,
layer='below',
line=dict(color='rgba(235,193, 238, 0.9)', width=0.5),
fillcolor= 'rgba(235,193, 238, 0.9)'
),
dict(type='rect',
xref='x2',
yref='y2',
x0=df['Date'].iloc[-60],
y0=3327226,
x1=df['Date'].iloc[-43],
y1=11801113,
layer='below',
line=dict(color='rgba(235,193, 238, 0.9)', width=0.5),
fillcolor= 'rgba(235,193, 238, 0.9)'
),
dict(type='rect',
xref='x1',
yref='y1',
x0=df['Date'].iloc[-60],
y0=130875,
x1=df['Date'].iloc[-43],
y1=375098,
layer='below',
line=dict(color='rgba(235,193, 238, 1)', width=0.5),
fillcolor= 'rgba(235,193, 238, 1)'
)]
)
fig2 = dict(data=[table_trace2, trace4, trace5, trace6], layout=layout2)
iplot(fig2)