Show Menu

PandasPlotting Cheat Sheet by

Sheet for Pandas Plotting


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()
- datafr­­ot(­x='­Non­e',­y='­None')
- data.p­lot.<k­ind­>()
Another method
'bar' or 'barh', 'hist', 'box', 'kde' or 'density' , 'hexbin', 'pie' and 'scatter'

Bar Plot

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

Area Plots

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

Pie plot

Pie plot for Series
- DataFr­­ot.p­ie­(su­bpl­ots­=True)
Pie plot for DataFrame
-­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­­att­er(x=' ', y=' ')
Scatter plot
-ax= df.plo­t.s­cat­ter­(x=­'A'­,y='B', color=­'None', label=­'Gr­oup1')­ot.s­ca­tte­r(x­='C­',y­='D', color=­'Ot­her', label=­'Gr­oup2', ax= ax)
Multiple plot


- 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­
Box plot
- dict={­'bo­xes':' ','whi­ske­rs':' ', 'media­ns':' ', 'caps': ' '}
Color of Boxes
- data.p­­x(c­olo­r=dict)
- data.p­­x(v­ert­=False)
Horizontal box plot
-­plo­t(c­olu­mn=[' ',' '], by=[' ',' ']))
- 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­­ot.h­ex­bin­(x=­'None', y='None')
Hexagonal bin plot
- DataFr­­ot.h­ex­bin­(x=­'None', y='None', C= 'z', reduce­_C_­fun­cti­on=­np.max)
add column 'z' for the value
- DataFr­­ot.h­ex­bin­(x=­'None', y='None', gridsize= 20)

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
-­dre­ws_­cur­ves­(data, 'column name with class names')

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

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

Plotting Tools from Pandas Plotting

> import­otting as pdt

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

Lag plot

Autoco­rre­lation plot

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

Plot formatting

Plot style

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

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

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

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

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

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


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

Plotting with errors bars

DataFr­­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­­ot(­table= True, ax=ax)

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

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

- DataFr­­ot(ax= ax)




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