Human: give me matplotlib cheatsheet
ChatGPT:
Here's a cheatsheet for Matplotlib:
Basics
pythonimport matplotlib.pyplot as plt
plt.plot(x, y) # plot x and y
plt.xlabel('x label') # set x-axis label
plt.ylabel('y label') # set y-axis label
plt.title('title') # set plot title
plt.legend() # add legend
plt.show() # display plot
Line Plot
pythonplt.plot(x, y, color='blue', linewidth=2, linestyle='--', marker='o',
markerfacecolor='red', markersize=8) # plot customization
Scatter Plot
pythonplt.scatter(x, y, s=50, c='green', alpha=0.5, edgecolors='none')
Bar Plot
pythonplt.bar(x, y, align='center', alpha=0.5)
Histogram
pythonplt.hist(x, bins=10, color='blue', edgecolor='black')
Subplots
pythonplt.subplots(nrows=2, ncols=2) # create 2x2 grid of subplots
ax1 = plt.subplot(2, 2, 1) # select first subplot
ax1.plot(x1, y1) # plot in first subplot
Annotations
pythonplt.text(x, y, 'text', fontsize=12) # add text annotation
plt.annotate('annotate', xy=(x,y), xytext=(a,b),
arrowprops=dict(facecolor='black', shrink=0.05)) # add arrow annotation
These are some of the most commonly used functions in Matplotlib. For more information, please refer to the official Matplotlib documentation.
Add a comment