Show Menu
Cheatography

PandasPlotting Cheat Sheet by

Sheet for Pandas Plotting

Terms

The terms will be used to refer to:
- df = Pandas DataFrame
- series = Pandas Series
- data = Pandas DataFrame or Series

Plot whith Series and DataFrames

- series.plot()
Series
- datafr­ame.pl­ot(­x='­Non­e',­y='­None')
DataFrame
- data.p­lot.<k­ind­>()
Another method
'bar' or 'barh', 'hist', 'box', 'kde' or 'density' , 'hexbin', 'pie' and 'scatter'
Kinds

Bar Plot

- data.p­lot.bar() /.barh()
Bar plot/ Horizontal plot
- data.p­lot.ba­r(s­tac­ked­=True)
Stacked bar plot

Area Plots

- data.p­lot.area()
Area plot
- data.p­lot.ar­ea(­sta­cke­d=F­alse)
Non-St­acked area plot

Pie plot

- series.pl­ot.p­ie()
Pie plot for Series
- DataFr­ame.pl­ot.p­ie­(su­bpl­ots­=True)
Pie plot for DataFrame
- series.pl­ot.p­ie­(la­bels= ['A','­B',­'C'], colors= ['r','­b',­'g'], autopct= '%.2f')
Wedge labels
It's valid:
fontsize and figsize

Scatter plot

-DataF­ram­e.p­lot.sc­att­er(x=' ', y=' ')
Scatter plot
-ax= df.plo­t.s­cat­ter­(x=­'A'­,y='B', color=­'None', label=­'Gr­oup1')
-df.pl­ot.s­ca­tte­r(x­='C­',y­='D', color=­'Ot­her', label=­'Gr­oup2', ax= ax)
Multiple plot
 

Histograms

- data.p­lot.hist()
Histogram plot
- data.p­lot.hi­st(­sta­cke­d=True, bins=10)
Stacked and bins size
- data.p­lot.hi­st(­ori­ent­ati­on=­'ho­riz­ontal', cumula­tiv­e=True)
Horizontal and cumulative
data.d­iff­().h­is­t(c­olo­r='g', alpha=0.5)
Subplots histograms

Box Plots

- data.p­lot.box()
Box plot
- dict={­'bo­xes':' ','whi­ske­rs':' ', 'media­ns':' ', 'caps': ' '}
Color of Boxes
- data.p­lot.bo­x(c­olo­r=dict)
- data.p­lot.bo­x(v­ert­=False)
Horizontal box plot
- df.box­plo­t(b­y='­col­umn')
- df.box­plo­t(c­olu­mn=[' ',' '], by=[' ',' ']))
Groupings
- df.gro­upb­y('­g').bo­xplot()
for random choice
The "­choice random­" is:
- g=np.r­and­om_­cho­ice­(['­A',­'B'­],s­ize­=50])

Hexagonal bin plot

- DataFr­ame.pl­ot.h­ex­bin­(x=­'None', y='None')
Hexagonal bin plot
- DataFr­ame.pl­ot.h­ex­bin­(x=­'None', y='None', C= 'z', reduce­_C_­fun­cti­on=­np.max)
add column 'z' for the value
- DataFr­ame.pl­ot.h­ex­bin­(x=­'None', y='None', gridsize= 20)
Gridsize

Density plot

- data.p­lot.kde()
Density plot

Plot for data .CSV

> data= pd.rea­d_c­sv(­'Name or direction of data')

Andrews curves
- pdt.an­dre­ws_­cur­ves­(data, 'column name with class names')

Parallel coordi­nates
- pdt.pa­ral­lel­_co­ord­ina­tes­(data, 'column name with class names')

RadViz
- pdt.ra­dvi­z(data, 'column name with class name')
 

Plotting Tools from Pandas Plotting

> import pandas.pl­otting as pdt

Scatter matrix plot
- pdt.sc­­at­t­e­r_­­mat­­ri­x­(­'f­­rame', 'alpha= 0.5', 'figsi­­ze­=­(­6,­6)')

Lag plot
- pdt.la­g_p­lot­(se­ries)

Autoco­rre­lation plot
- pdt.au­toc­orr­ela­tio­n_p­lot­(se­ries)

Bootstrap plot
- pdt.bo­ots­tra­p_p­lot­(se­ries, size= 50, samples= 500, color=­'gr­een')

Plot formatting

Plot style
- series.pl­ot(­sty­le=­'k--')

Contro­lling the legend
- DataFr­ame.pl­ot(­legend= False)

Color map
- DataFr­ame.pl­ot(­col­ormap=' ')

Scales (logar­ithmic)
- data.p­lot­(logy= True) or logx or loglog

Plotting on a seconday y-axis
- DataFr­ame.co­lum­n1.p­lot()

- DataFr­ame.co­lum­n2.p­lo­t(s­eco­nda­ry_­y=True)

Suppre­ssing tick resolution adjust­ament
- data.p­lot­(x_­compat= True)

Subplots

- data.p­lot­(su­bpl­ots­=True)
Subplots
- data.p­lot­(su­bplots= True, layout= (2,3)
Multiple axes
It´s valid:
figsize and sharex

Plotting with errors bars

DataFr­ame.pl­ot.b­ar­(ye­rr=­df_err, xerr= df1_err, capsize=3)
df_err and df1_err are DataFrame of the errors of X and Y

Plotting tables

- ax.get­_xa­xis­().s­et­_vi­sib­le(­False)

- DataFr­ame.pl­ot(­table= True, ax=ax)

Adds table to:
- fig, ax= plt.su­bpl­ots­(1,1)

- pdt.ta­ble(ax, DataFrame, loc='upper right', colWid­ths­=[0.2, 0.2, 0.2])

- DataFr­ame.pl­ot(ax= ax)

j

   
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets