Plotly and Cufflinks : Advanced Python Data Visualization Libraries
Tags: machinelearning, beginners, python, programming
Published: 2022-12-30 09:54:33

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]})
```
**Output:**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xithmv2khauv3a7rok9b.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g87cqo925dshbmdlu7x8.png)

## Scatter Plot

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1bcey1tip4apkywpzmpc.png)

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')
```
**Output:**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n8slov8c5n8koz69zzsw.png)



## Box Plot

```
df.iplot(kind='box')
```
**Output:**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uekxmiejssphmtop932p.png)



## 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')
```
**Output:**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f2sfgcvwzttyvqvj6jfb.png)



## Histogram

```
df['A'].iplot(kind='hist',bins=50)
```
**Output:**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/04yasu73l53h7cdnxats.png)


## Spread Plot

```
df[['A','B']].iplot(kind='spread')
```
**Output:**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/su82knuew4qztl8ed7pt.png)
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')
```
**Output:**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cqnnsif2ilzcgyd4gw9z.png)

## Scatter matrix

```
df.scatter_matrix()
```
**Output:**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5si13mgda4si2xeqmb0o.png)

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