Python | Build various graphics using plot and cufflinks



cufflink connects tightly with pandas to directly create graphs and data charts.  choropleth is used to describe a geographic representation of the United States. choropleth is used in world mapping and more.

Let`s plot different types of graphs like boxplot, spreadplot, etc. using plotly and cufflinks.

Command install tight:

 pip install plotly 

Command to install cufflink:

 pip install cufflink 

Code # 1: Show data frame

# import all required libraries

import pandas as pd

import numpy as np

 

% matplotlib inline

from plotly import __ version__

import cufflinks as cf

 

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

 
# to get the connection

init_notebook_mode (connected = True )

  
# the plot also serves online,
# but we only use a sample
cf.go_offline

 
# creating data frames

df  = pd.DataFrame (np.random.randn ( 100 , 4 ), columns = `ABCD` . split ())

  

df2 = pd .DataFrame ({ `Category` : [ ` A` , `B` , `C` ], ` Values` : [ 32 , 43 , 50 ]})

df2.he ad ()

Output:

Code # 2: Normal area

# plot function
df.iplot ()

Output:

Code # 3: dot plot

# markers made to point to the graph

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

Output:

Code # 4: box section

# boxplot

df.iplot (kind = `box` )

Output:

Code # 5: Data Graph

# create a data frame with three axes

df3 = pd.DataFrame ({ `x` : [ 1 , 2 , 3 , 4 , 5 ],

`y` : [ 10 , 20 , 30 , 20 , 10 ],

  `z` : [ 5 , 4 , 3 , 2 , 1 ]})

Output:

Code # 6: Surface area

# site surface
# color scale: red (rd), yellow (yl), blue (bu)

df3.iplot (kind = ` surface` , colorscale = `r dylbu` )

Output: