DEV Community

Cover image for Plotly and Cufflinks : Advanced Python Data Visualization Libraries
Zaynul Abedin Miah
Zaynul Abedin Miah

Posted on

Plotly and Cufflinks : Advanced Python Data Visualization Libraries

A Python library called plotly is used to make graphs, especially interactive graphs. It can make graphs and charts like histograms, barplots, boxplots, spreadplots, and many more. It is mostly used for data analysis and analysis of money. plotly is a library for making interactive charts and graphs.

Cufflink links plotly to pandas so that graphs and charts can be made directly from dataframes. The word "choropleth" is used to describe a map of the United States. Choropleth is used to make world maps and many other things.

Example:

Setting up a dataframe with pandas and numpy library.



import pandas as pd
import numpy as np
%matplotlib inline
#import plotly and cufflinks
from plotly import __version__
import cufflinks as cf
#DATA
df = pd.DataFrame(np.random.randn(100,4),columns='A B C D'.split())
df.head()
df2 = pd.DataFrame({'Category':['A','B','C'],'Values':[32,43,50]})


Enter fullscreen mode Exit fullscreen mode

Output:

Image description

Image description

Scatter Plot



df.iplot(kind='scatter',x='A',y='B',mode='markers')


Enter fullscreen mode Exit fullscreen mode

Output:

Image description

The term "interactive plot" refers to iplot. Plotly reads code written in Python and generates charts written in JavaScript that look stunning. You can zoom in to take out values and you can also zoom out and also use tools available.

Bar Plot



df2.iplot(kind='bar',x='Category',y='Values')


Enter fullscreen mode Exit fullscreen mode

Output:

Image description

Box Plot



df.iplot(kind='box')


Enter fullscreen mode Exit fullscreen mode

Output:

Image description

Surface Plot:



df3=pd.DataFrame({'x':[1,2,3,4,5],'y':[10,20,30,40,50],'z':[5,4,3,2,1]})
df3.iplot(kind='surface',colorscale='rdylbu')


Enter fullscreen mode Exit fullscreen mode

Output:

Image description

Histogram



df['A'].iplot(kind='hist',bins=50)


Enter fullscreen mode Exit fullscreen mode

Output:

Image description

Spread Plot



df[['A','B']].iplot(kind='spread')


Enter fullscreen mode Exit fullscreen mode

Output:

Image description
It is quite essential for stock datas to see the spread between 2 datas.

Bubble Plot



df.iplot(kind='bubble',x='A',y='B',size='C')


Enter fullscreen mode Exit fullscreen mode

Output:

Image description

Scatter matrix



df.scatter_matrix()


Enter fullscreen mode Exit fullscreen mode

Output:

Image description

With scatter matrix you may need to be careful when dealing with large data as this might take a while to load. And you might even crash your python kernal.

If you are interested in financial analyst you can check out some functions here like moving averages, correlation between plots etc..:
https://github.com/santosjorge/cufflinks/blob/b973f3a0f689816139de6c68855ab65ffec15567/cufflinks/ta.py

Top comments (0)