matplotlib

Types of Plots

Function

Chapter

Description

plt.scatter(x, y)

Data Visualization

Creates a scatter plot of the variable x against the variable y

plt.plot(x, y)

Data Visualization

Creates a line plot of the variable x against the variable y

plt.hist(x, bins=None)

Data Visualization

Creates a histogram of x. Bins argument can be an integer or sequence

plt.bar(x, height)

Data Visualization

Creates a bar plot. x specifies x-coordinates of bars, height specifies heights of the bars

plt.axvline(x=0)

Data Visualization

Creates a vertical line at the x value specified

plt.axhline(y=0)

Data Visualization

Creates a horizontal line at the y value specified

Plot additions

Function

Chapter

Description

%matplotlib inline

Data Visualization

Causes output of plotting commands to be displayed inline

plt.figure(figsize=(3, 5))

Data Visualization

Creates a figure with a width of 3 inches and a height of 5 inches

plt.xlim(xmin, xmax)

Data Visualization

Sets the x-limits of the current axes

plt.xlabel(label)

Data Visualization

Sets an x-axis label of the current axes

plt.title(label)

Data Visualization

Sets a title of the current axes

plt.legend(x, height)

Data Visualization

Places a legend on the axes

fig, ax = plt.subplots()

Data Visualization

Creates a figure and set of subplots

plt.show()

Data Visualization

Displays a figure