Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
17 views

Cheat Sheet Plotting With Matplotlib Using Pandas

Uploaded by

Andres Rincon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Cheat Sheet Plotting With Matplotlib Using Pandas

Uploaded by

Andres Rincon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

5/10/23, 18:17 about:blank

Data Visualization with Python


Cheat Sheet : Plotting with Matplotlib using Pandas
Plot Type Description Pandas Function Example Visual

Shows trends and changes DataFrame.plot.line()


Line Plot df.plot(x=’year’, y=’sales’, kind=’line’)
over time DataFrame.plot(kind = ‘line’)

Displays data series as


DataFrame.plot.area()
Area Plot filled areas, showing the DataFrame.plot(kind = ‘area’)
df.plot(kind='area')
relationship between them

Displays bars representing


Series.plot.hist() s.plot(kind='hist', bins=10)
Histogram the data count in each Series.plot(kind = ‘hist’, bins = n) df[‘age’].plot(kind='hist', bins=10)
interval/bin

Displays data using DataFrame.plot.bar()


Bar Chart df.plot(kind='bar')
rectangular bars DataFrame.plot(kind = ‘bar’)

Displays data as a circular Series.plot.pie()


plot divided into slices, Series.plot(kind = ‘pie’) s.plot(kind='pie’,autopct='%1.1f%%')
Pie Chart
representing proportions or DataFrame.plot.pie(y, labels) df.plot(x='Category',y='Percentage',kind='pie')
percentages of a whole DataFrame.plot(kind = ‘pie’)

Displays the distribution of


DataFrame.plot.box()
Box Plot a dataset along with key DataFrame.plot(kind = ‘box’)
df_can.plot(kind='box')
statistical measures

Uses Cartesian coordinates


DataFrame.plot.scatter()
Scatter Plot to display values for two DataFrame.plot(x, y, kind = ‘scatter’)
df.plot(x='Height', y='Weight', kind='scatter')
variables

Cheat Sheet : Plotting directly with Matplotlib


Plot Type Description Matplotlib Function Example Visual

Shows trends and changes


Line Plot plt.plot() plt.plot(x, y, color='red', linewidth=2)
over time

about:blank 1/2
5/10/23, 18:17 about:blank
Plot Type Description Matplotlib Function Example Visual

Display data series as filled plt.fill_between(x, y1, y2, color='blue',


Area Plot plt.fill_between()
areas alpha=0.5)

Displays bars representing


plt.hist(data, bins=10, color='orange',
Histogram the data count in each plt.hist()
edgecolor='black')
interval/bin

Displays data using plt.bar(x, height, color='green',


Bar Chart plt.bar()
rectangular bars width=0.5)

Displays data as a circular


plot divided into slices, plt.pie(sizes, labels=labels,
Pie Chart plt.pie()
representing proportions or colors=colors, explode=explode)
percentages of a whole

Displays the distribution of


Box Plot a dataset along with key plt.boxplot() plt.boxplot(data, notch=True)
statistical measures

Uses Cartesian coordinates


plt.scatter(x, y, color='purple',
Scatter Plot to display values for two plt.scatter()
marker='o', s=50)
variables

Creating multiple plots on fig, axes = plt.subplots(nrows=2,


Subplotting plt.subplots()
one figure ncols=2)

plt.title('Title')
Customizing plot: adding plt.xlabel('X Label')
Customization Various customization plt.ylabel('Y Label')
labels, title, legend, grid plt.legend()
plt.grid(True)

Author(s)
Dr. Pooja

Changelog
Date Version Changed by Change Description
2023-06-10 0.1 Dr. Pooja Initial version created

about:blank 2/2

You might also like