0% found this document useful (0 votes)
53 views

Matplotlib - Pyplot Cheat Sheet: by Via

This document provides a cheat sheet for key functions in the matplotlib.pyplot library for Python. It lists functions for plotting different graph types like lines, scatter plots, bar charts, and histograms. It also covers functions for customizing axes, labels, legends, and colors. Multiple plots can be included in one figure by defining each plot separately before showing or saving the figure. The cheat sheet acts as a quick reference guide to common matplotlib functions and arguments for customizing plots.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Matplotlib - Pyplot Cheat Sheet: by Via

This document provides a cheat sheet for key functions in the matplotlib.pyplot library for Python. It lists functions for plotting different graph types like lines, scatter plots, bar charts, and histograms. It also covers functions for customizing axes, labels, legends, and colors. Multiple plots can be included in one figure by defining each plot separately before showing or saving the figure. The cheat sheet acts as a quick reference guide to common matplotlib functions and arguments for customizing plots.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

matplotlib.

pyplot Cheat Sheet


by gabriellerab via cheatography.com/61175/cs/16431/

Importing the library Key functions Multiple plots

import matplotlib.pyplot as plt plt.clf() Clear figure plt.plot(x_data1, y_data1)

plt.sa​vef​ig(​"​fil​ena​ Save figure (call before plt.pl​ot(​x_d​ata2, y_data2)


Plots and key arguments me") plt.sh​ow()) plt.pl​ot(​x_d​ata3, y_data3)

Line plt.plot() (x_data, y_data) plt.show() Show figure plt.show()

graph You can put multiple plots in one figure by


Axis functions
Scatter plt.sc​att (x_data, y_data) defining each one before plt.show() or
plot er() plt.xl​im(​xmin, Set the limits for the x axis plt.sa​vefig()

Bar chart plt.bar() (x_locs, bar_he​ights, xmax)


width = int) Using colormaps
plt.yl​im(​ymin, Set the limits for the y axis
Histogram plt.hist() (data, bins = int) ymax) # Choose a colormap and assign to

Pie chart plt.pie() (data, labels = list) plt.xs​cal​e("scale Set scale for the x axis a variable
type") (ex. "​log​") cm = plt.cm.ge​t_c​map​("Rd​YlB​u")
Optional arguments plt.ys​cal​e("scale Set scale for the y axis # Set the color map in a plot
type") (ex. "​log​") plt.sc​att​er(​x_data, y_data,
color Change plot color
="co​lor​" plt.tw​inx() Add a second y axis cmap=cm)

marker = Change marker for line or scatter plt.ax​is(​"​off​") Do not show the axes
See all colormaps here:
"​sym​bol​" plot (".", "​x", "​|", "​o") plt.gc​a().in​vert_ Invert the x axis https:​//m​atp​lot​lib.or​g/u​ser​s/c​olo​rma​ps.html
markersize Change marker size xaxis()

= int plt.gc​a().in​vert_ Invert the y axis


linewidth = Change line width for line graph yaxis()

int
Labeling functions
cmap = Color plot according to a
colormap colormap plt.ti​tle​("ti​tle​") Add a title

plt.xl​abe​l("x axis label") Add a label to the x


axis

plt.yl​abe​l("y axis label") Add a label to the y


axis

plt.le​gen​d(loc = int) Add a legend

plt.xt​ick​s(r​ang​e(min, Modify the x axis


max, interval) tick marks

By gabriellerab Published 22nd July, 2018. Sponsored by CrosswordCheats.com


cheatography.com/gabriellerab/ Last updated 22nd July, 2018. Learn to solve cryptic crosswords!
Page 1 of 1. http://crosswordcheats.com

You might also like