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

- 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­­ea()
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

-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­­att­er(­x='­C',­y='D', color=­'Ot­her', label=­'Gr­oup2', ax= ax)
Multiple plot


- 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

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

DataF­ram­e.p­­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­­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)



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


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