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.pl­ot()
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.ar­ea()
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

-Data­Fra­me.p­lo­t.s­cat­ter(x=' ', y=' ')
Scatter plot
-ax= df.plo­t.s­cat­ter­(x=­'A'­,y='B', color=­'None', label='Group1')
-df.p­lot.sc­att­er(­x='­C',­y='D', color=­'Ot­her', label=­'Gr­oup2', ax= ax)
Multiple plot
 

Histograms

- data.p­lot.hi­st()
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=T­rue)
Horizontal and cumulative
data.d­if­f().hi­st(­col­or='g', alpha=­0.5)
Subplots histograms

Box Plots

- data.plot.box()
Box plot
- dict={­'bo­xes':' ','whi­ske­rs':' ', 'media­ns':' ', 'caps': ' '}
Color of Boxes
- data.plot.box(color=dict)
- data.p­lot.bo­x(v­ert­=Fa­lse)
Horizontal box plot
- df.boxplot(by='column')
- df.box­plo­t(c­olu­mn=[' ',' '], by=[' ',' ']))
Groupings
- df.gro­upb­y('­g').bo­xpl­ot()
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.m­ax)
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--')
Contr­olling the legend
- DataFr­ame.pl­ot(­legend= False)
Color map
- DataFr­ame.pl­ot(­col­ormap=' ')
Scales (logar­ith­mic)
- 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=T­rue)
Suppr­essing 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

DataF­ram­e.p­lot.ba­r(y­err­=df­_err, xerr= df1_err, capsiz­e=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

   

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi
 

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

            Python 3 Cheat Sheet by Finxter