matplotlib-cheat-sheet
matplotlib-cheat-sheet
This cheat sheet provides a quick reference for essential Importing Libraries
Advanced Plot Customization
plotting functions in matplotlib, helping you create and IMPORT
SUBPLOTS, SPINES, TICK_PARAMS, TICK_TOP
histograms and bar charts—and includes advanced PLOT,SCATTER, BAR, BARH, HIST, AREA,
PIE
customization options like subplots, color mapping, and Pandas Visualization
annotations.
Syntax for How to use Explained Syntax for How to use Explained
default theme
sns.set_theme()
SCATTER plt.scatter(x_values, y_values) Create a scatter plot of points
plt.show()
Import pandas using its
import pandas as pd
common alias
plt.scatter(x_values, y_values,
Customize point color and
Apply the fivethirtyeight size
import matplotlib.style as style c='red', s=100)
predefined style
style.use('fivethirtyeight') plt.show()
plt.hist(data_column)
plt.plot(x_values2, y_values2)
plt.show()
Syntax for How to use Explained Syntax for How to use Explained
label='Label 2')
plt.show() w
bet een y1 and y2 plt.show()
autopct='%1.1f%%')
percentages plt.show() and font size
plt.show()
Customization
Customize the tick labels on
SET_XTICKS plt.xticks(ticks=x_values, labels=labels)
the x-axis
Syntax for How to use Explained
plt.ticklabel_format(axis='both',
Change scientific notation to
_FORMAT
style='plain') plain text
YLABEL plt.ylabel('Y-axis Label') Add a label to the y-axis
Syntax for How to use Explained Syntax for How to use Explained
plt.show()
ANNOTATE plt.annotate(
Add text and an arrow
'Text', xy=(x, y),
annotation on the plot
xytext=(x_offset, y_offset),
arrowprops=dict(facecolor='black',
Advanced Plot Customization
shrink=0.05)
ax.bar(x, height)
plt.plot(x_values, y_values)
plt.show()
TEXT SCATTER
DataFrame.plot.scatter(x='column1',
Create a scatter plot from a
ax.text(x, y, 'Sample Text', fontsize=12,
Add custom text to a specific
position on the plot
(DATAFRAME) y='column2')
DataFrame object
color='blue')
plt.show()
plt.show()
AXHLINE Add a horizontal line at a
ax.axhline(y=3, color='green',
Series object
plt.show()
edgecolor='black')
spacing and custom colors
linewidths=0.5, cmap='Blues')
plt.show()
multiple attributes
hue='hue_var', size='size_var',
style='style_var')
plt.show()
plt.show()