In [5]:
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.image as image
%matplotlib inline

In [6]:
import plotly.plotly as py
import plotly.tools as tls
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)



In [2]:
start='20130428'
end='20181118'

In [7]:
def plotter(currency,i,c='orange',st='2012-12-20',last='2017'):
    dfs=pd.read_html('https://coinmarketcap.com/currencies/'+currency+'/historical-data/?start='+start+'&end='+end)
    df=dfs[0]
    df=df[['Date','Close**']]
    df.columns=['Date','.']
    df['Date']=pd.to_datetime(df['Date'])
    fig,ax=plt.subplots(figsize=(13,6))
    df[(last>df['Date'])&(df['Date']>'2013')].set_index('Date').plot(ax=ax,c='grey')
    ax2=ax.twiny()
    ax2=ax2.twinx()
    dz=df[df['Date']>'2017'].set_index('Date')
    dz.columns=[u'Before and after the last bubble\n2013-2016 (bottom + left axis)']
    dz.plot(ax=ax2,c='grey')
    dz.columns=[currency.capitalize()+u' price in $ since 2017 (top + right axis)']
    dz.plot(ax=ax2,c=c)
    ax.set_xlim(st,pd.to_datetime(st)+pd.to_timedelta(3, unit='Y'))
    ax2.set_xlim('2017','2020')
    ax.set_xlabel('')
    ax2.legend()
    im = image.imread('https://s2.coinmarketcap.com/static/img/coins/32x32/'+str(i)+'.png')
    ax3 = fig.add_axes([0.12, 0.74, 0.07, 0.07])
    ax3.axis('off')
    ax3.imshow(im)
    ax3.set_title(str(int(max(df[df['Date']>'2017']['.'])/max(df[df['Date']<'2017']['.'])))+'x',color=c,)
    plt.savefig(currency)
    return fig

In [21]:
currency='bitcoin'
c='orange'
st='2012-12-20'
last='2017'
i=1
dfs=pd.read_html('https://coinmarketcap.com/currencies/'+currency+'/historical-data/?start='+start+'&end='+end)
df=dfs[0]
df=df[['Date','Close**']]
df.columns=['Date','.']
df['Date']=pd.to_datetime(df['Date'])
fig,ax=plt.subplots(figsize=(13,6))
df[(last>df['Date'])&(df['Date']>'2013')].set_index('Date').plot(ax=ax,c='grey')
ax2=ax.twiny()
ax2=ax2.twinx()
dz=df[df['Date']>'2017'].set_index('Date')
dz.columns=[u'Before and after the last bubble\n2013-2016 (bottom + left axis)']
#dz.plot(ax=ax2,c='grey')
dz.columns=[currency.capitalize()+u' price in $ since 2017 (top + right axis)']
dz.plot(ax=ax2,c=c)
#ax.set_xlim(st,pd.to_datetime(st)+pd.to_timedelta(3, unit='Y'))
#ax2.set_xlim('2017','2020')
#ax.set_xlabel('')
#ax2.legend()
#im = image.imread('https://s2.coinmarketcap.com/static/img/coins/32x32/'+str(i)+'.png')
#ax3 = fig.add_axes([0.12, 0.74, 0.07, 0.07])
#ax3.axis('off')
#ax3.imshow(im)
#ax3.set_title(str(int(max(df[df['Date']>'2017']['.'])/max(df[df['Date']<'2017']['.'])))+'x',color=c,)
#plt.savefig(currency)
plotly_fig = tls.mpl_to_plotly(fig)
plotly_fig["layout"]["showlegend"] = True
plotly_fig["layout"]['hovermode'] = 'x'
iplot(plotly_fig, filename='ons1')


C:\Users\csala\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\ipykernel_launcher.py:10: SettingWithCopyWarning:


A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

C:\Users\csala\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\plotly\matplotlylib\renderer.py:390: UserWarning:

Bummer! Plotly can currently only draw Line2D objects from matplotlib that are in 'data' coordinates!

C:\Users\csala\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\plotly\matplotlylib\renderer.py:487: UserWarning:

I found a path object that I don't think is part of a bar chart. Ignoring.

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-21-89639a7fc4f9> in <module>()
     28 #ax3.set_title(str(int(max(df[df['Date']>'2017']['.'])/max(df[df['Date']<'2017']['.'])))+'x',color=c,)
     29 #plt.savefig(currency)
---> 30 plotly_fig = tls.mpl_to_plotly(fig)
     31 plotly_fig["layout"]["showlegend"] = True
     32 plotly_fig["layout"]['hovermode'] = 'x'

~\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\plotly\tools.py in mpl_to_plotly(fig, resize, strip_style, verbose)
    467     if matplotlylib:
    468         renderer = matplotlylib.PlotlyRenderer()
--> 469         matplotlylib.Exporter(renderer).run(fig)
    470         if resize:
    471             renderer.resize()

~\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\plotly\matplotlylib\mplexporter\exporter.py in run(self, fig)
     47             import matplotlib.pyplot as plt
     48             plt.close(fig)
---> 49         self.crawl_fig(fig)
     50 
     51     @staticmethod

~\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\plotly\matplotlylib\mplexporter\exporter.py in crawl_fig(self, fig)
    114                                        props=utils.get_figure_properties(fig)):
    115             for ax in fig.axes:
--> 116                 self.crawl_ax(ax)
    117 
    118     def crawl_ax(self, ax):

~\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\plotly\matplotlylib\mplexporter\exporter.py in crawl_ax(self, ax)
    128                 if(hasattr(text, 'get_text') and text.get_text()):
    129                     self.draw_text(ax, text, force_trans=ax.transAxes,
--> 130                                    text_type=ttp)
    131             for artist in ax.artists:
    132                 # TODO: process other artists

~\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\plotly\matplotlylib\mplexporter\exporter.py in draw_text(self, ax, text, force_trans, text_type)
    209                                     coordinates=coords,
    210                                     text_type=text_type,
--> 211                                     style=style, mplobj=text)
    212 
    213     def draw_patch(self, ax, patch, force_trans=None):

~\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\plotly\matplotlylib\renderer.py in draw_text(self, **props)
    518         """
    519         self.msg += "    Attempting to draw an mpl text object\n"
--> 520         if not mpltools.check_corners(props['mplobj'], self.mpl_fig):
    521             warnings.warn(
    522                 "Looks like the annotation(s) you are trying \n"

~\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\plotly\matplotlylib\mpltools.py in check_corners(inner_obj, outer_obj)
     40 
     41 def check_corners(inner_obj, outer_obj):
---> 42     inner_corners = inner_obj.get_window_extent().corners()
     43     outer_corners = outer_obj.get_window_extent().corners()
     44     if inner_corners[0][0] < outer_corners[0][0]:

~\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\matplotlib\text.py in get_window_extent(self, renderer, dpi)
    918             self._renderer = renderer
    919         if self._renderer is None:
--> 920             raise RuntimeError('Cannot get window extent w/o renderer')
    921 
    922         bbox, info, descent = self._get_layout(self._renderer)

RuntimeError: Cannot get window extent w/o renderer

In [9]:
plotter('bitcoin',1,'orange')


C:\Users\csala\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning:


A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

Out[9]:

In [8]:
plotly_fig = tls.mpl_to_plotly(plotter('bitcoin',1,'orange'))
plotly_fig["layout"]["showlegend"] = True
plotly_fig["layout"]['hovermode'] = 'x'
iplot(plotly_fig, filename='ons1')


C:\Users\csala\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning:


A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

C:\Users\csala\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\plotly\matplotlylib\renderer.py:390: UserWarning:

Bummer! Plotly can currently only draw Line2D objects from matplotlib that are in 'data' coordinates!

C:\Users\csala\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\plotly\matplotlylib\renderer.py:487: UserWarning:

I found a path object that I don't think is part of a bar chart. Ignoring.

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-8-8d22edf5a92c> in <module>()
----> 1 plotly_fig = tls.mpl_to_plotly(plotter('bitcoin',1,'orange'))
      2 plotly_fig["layout"]["showlegend"] = True
      3 plotly_fig["layout"]['hovermode'] = 'x'
      4 iplot(plotly_fig, filename='ons1')

~\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\plotly\tools.py in mpl_to_plotly(fig, resize, strip_style, verbose)
    467     if matplotlylib:
    468         renderer = matplotlylib.PlotlyRenderer()
--> 469         matplotlylib.Exporter(renderer).run(fig)
    470         if resize:
    471             renderer.resize()

~\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\plotly\matplotlylib\mplexporter\exporter.py in run(self, fig)
     47             import matplotlib.pyplot as plt
     48             plt.close(fig)
---> 49         self.crawl_fig(fig)
     50 
     51     @staticmethod

~\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\plotly\matplotlylib\mplexporter\exporter.py in crawl_fig(self, fig)
    114                                        props=utils.get_figure_properties(fig)):
    115             for ax in fig.axes:
--> 116                 self.crawl_ax(ax)
    117 
    118     def crawl_ax(self, ax):

~\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\plotly\matplotlylib\mplexporter\exporter.py in crawl_ax(self, ax)
    128                 if(hasattr(text, 'get_text') and text.get_text()):
    129                     self.draw_text(ax, text, force_trans=ax.transAxes,
--> 130                                    text_type=ttp)
    131             for artist in ax.artists:
    132                 # TODO: process other artists

~\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\plotly\matplotlylib\mplexporter\exporter.py in draw_text(self, ax, text, force_trans, text_type)
    209                                     coordinates=coords,
    210                                     text_type=text_type,
--> 211                                     style=style, mplobj=text)
    212 
    213     def draw_patch(self, ax, patch, force_trans=None):

~\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\plotly\matplotlylib\renderer.py in draw_text(self, **props)
    518         """
    519         self.msg += "    Attempting to draw an mpl text object\n"
--> 520         if not mpltools.check_corners(props['mplobj'], self.mpl_fig):
    521             warnings.warn(
    522                 "Looks like the annotation(s) you are trying \n"

~\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\plotly\matplotlylib\mpltools.py in check_corners(inner_obj, outer_obj)
     40 
     41 def check_corners(inner_obj, outer_obj):
---> 42     inner_corners = inner_obj.get_window_extent().corners()
     43     outer_corners = outer_obj.get_window_extent().corners()
     44     if inner_corners[0][0] < outer_corners[0][0]:

~\AppData\Local\Continuum\anaconda2\envs\python3\lib\site-packages\matplotlib\text.py in get_window_extent(self, renderer, dpi)
    918             self._renderer = renderer
    919         if self._renderer is None:
--> 920             raise RuntimeError('Cannot get window extent w/o renderer')
    921 
    922         bbox, info, descent = self._get_layout(self._renderer)

RuntimeError: Cannot get window extent w/o renderer

In [5]:
plotter('litecoin',2,'lightgrey')


C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  

In [6]:
plotter('ripple',52,'black','2012-11-30')


C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  

In [7]:
plotter('dash',131,'dodgerblue','2013-06-07')


C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  

In [8]:
plotter('namecoin',3,'lightsteelblue','2012-11-18')


C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  

In [9]:
plotter('dogecoin',74,'darkkhaki','2013-01-22')


C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  

In [10]:
plotter('bytecoin-bcn',372,'deeppink','2013-02-15')


C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  

In [11]:
plotter('nxt',66,'deepskyblue','2013-06-15')


C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  

In [16]:
plotter('nem',873,'mediumturquoise','2015-06-25','2017-02')


C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  

In [13]:
plotter('peercoin',5,'limegreen')


C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  

In [14]:
plotter('feathercoin',8,'black','2012-11-20')


C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  

In [ ]: