matplotlib.
pyplot Cheat Sheet
by gabriellerab via [Link]/61175/cs/16431/
Importing the library Key functions Multiple plots
import [Link] as plt [Link]() Clear figure [Link](x_data1, y_data1)
[Link]vefig("filena Save figure (call before [Link]ot(x_data2, y_data2)
Plots and key arguments me") [Link]ow()) [Link]ot(x_data3, y_data3)
Line [Link]() (x_data, y_data) [Link]() Show figure [Link]()
graph You can put multiple plots in one figure by
Axis functions
Scatter [Link]att (x_data, y_data) defining each one before [Link]() or
plot er() [Link]im(xmin, Set the limits for the x axis [Link]vefig()
Bar chart [Link]() (x_locs, bar_heights, xmax)
width = int) Using colormaps
[Link]im(ymin, Set the limits for the y axis
Histogram [Link]() (data, bins = int) ymax) # Choose a colormap and assign to
Pie chart [Link]() (data, labels = list) [Link]cale("scale Set scale for the x axis a variable
type") (ex. "log") cm = [Link]t_cmap("RdYlBu")
Optional arguments [Link]cale("scale Set scale for the y axis # Set the color map in a plot
type") (ex. "log") [Link]atter(x_data, y_data,
color Change plot color
="color" [Link]inx() Add a second y axis cmap=cm)
marker = Change marker for line or scatter [Link]is("off") Do not show the axes
See all colormaps here:
"symbol" plot (".", "x", "|", "o") [Link]a().invert_ Invert the x axis https://matplot[Link]g/users/colorma[Link]
markersize Change marker size xaxis()
= int [Link]a().invert_ Invert the y axis
linewidth = Change line width for line graph yaxis()
int
Labeling functions
cmap = Color plot according to a
colormap colormap [Link]tle("title") Add a title
[Link]abel("x axis label") Add a label to the x
axis
[Link]abel("y axis label") Add a label to the y
axis
[Link]gend(loc = int) Add a legend
[Link]icks(range(min, Modify the x axis
max, interval) tick marks
By gabriellerab Published 22nd July, 2018. Sponsored by [Link]
[Link]/gabriellerab/ Last updated 22nd July, 2018. Learn to solve cryptic crosswords!
Page 1 of 1. [Link]