/ Python And R Data science skills: 95 plotly AND CUFFLINKS iplot 01

Sunday 18 February 2018

95 plotly AND CUFFLINKS iplot 01

95 plotly AND CUFFLINKS iplot 01

Plotly is a library that allows you to create interactive plots that you can use in dashboards or websites (you can save them as html files or static images).

Installation

In order for this all to work, you'll need to install plotly and cufflinks to call plots directly off of a pandas dataframe. These libraries are not currently available through conda but are available through pip. Install the libraries at your command line/terminal using:

pip install plotly
pip install cufflinks

NOTE: Make sure you only have one installation of Python on your computer when you do this, otherwise the installation may not work.

Imports and Set-up

In [1]:
import pandas as pd
import numpy as np
%matplotlib inline
In [2]:
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

print(__version__) # requires version >= 1.9.0
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-8a5d711e0cb1> in <module>()
----> 1 from plotly import __version__
      2 from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
      3 
      4 print(__version__) # requires version >= 1.9.0

ModuleNotFoundError: No module named 'plotly'
In [3]:
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

print(__version__) # requires version >= 1.9.0
2.3.0
In [4]:
import cufflinks as cf
In [5]:
init_notebook_mode(connected=True)
In [6]:
cf.go_offline()
IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--NotebookApp.iopub_data_rate_limit`.
In [13]:
df1 = pd.DataFrame(np.random.randn(100,4),columns='A B C D'.split())
In [8]:
df2 = pd.DataFrame({'Category':['A','B','C'],'Values':[32,43,50]})
In [14]:
df1.head()
Out[14]:
A B C D
0 0.167593 -0.177199 -0.342331 0.830434
1 0.557206 0.103434 -1.133301 -1.023257
2 0.120307 0.451010 -1.217021 -1.065998
3 0.768557 1.732634 0.168443 0.899072
4 0.220524 -0.163088 0.393181 0.337887
In [15]:
df2.head()
Out[15]:
Category Values
0 A 32
1 B 43
2 C 50
  • scatter
  • bar
  • box
  • spread
  • ratio
  • heatmap
  • surface
  • histogram
  • bubble
In [16]:
df.plot()
Out[16]:
<matplotlib.axes._subplots.AxesSubplot at 0xb8e8400>
In [17]:
df.iplot()

No comments:

Post a Comment