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
In [3]:
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
print(__version__) # requires version >= 1.9.0
In [4]:
import cufflinks as cf
In [5]:
init_notebook_mode(connected=True)
In [6]:
cf.go_offline()
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]:
In [15]:
df2.head()
Out[15]:
Using Cufflinks and iplot()¶
- scatter
- bar
- box
- spread
- ratio
- heatmap
- surface
- histogram
- bubble
In [16]:
df.plot()
Out[16]:
In [17]:
df.iplot()
No comments:
Post a Comment