0% found this document useful (0 votes)
6 views2 pages

Matplotlib Cheatsheet

This document is a cheatsheet for Matplotlib, providing essential commands and explanations for creating various types of plots including line, scatter, bar, histogram, and pie charts. It covers customization options for titles, labels, legends, and styles, as well as how to create subplots and save plots in different formats. Additionally, it outlines common use cases for each plot type.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Matplotlib Cheatsheet

This document is a cheatsheet for Matplotlib, providing essential commands and explanations for creating various types of plots including line, scatter, bar, histogram, and pie charts. It covers customization options for titles, labels, legends, and styles, as well as how to create subplots and save plots in different formats. Additionally, it outlines common use cases for each plot type.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

■ Matplotlib Cheatsheet (with Explanations)

1. Import
import [Link] as plt
2. Basic Plot
[Link]([1,2,3,4], [10,20,25,30]) # Line plot (x,y)
[Link]() # Display the plot
3. Plot Types
[Link](x,y) # Line plot
[Link](x,y) # Scatter plot
[Link](x,heights) # Bar chart (vertical)
[Link](y,widths) # Horizontal bar chart
[Link](data, bins=10) # Histogram
[Link](sizes, labels=labels) # Pie chart
4. Titles, Labels, Legends
[Link]("My Plot") # Title
[Link]("X-axis") # X label
[Link]("Y-axis") # Y label
[Link](["Series1","Series2"]) # Legend
5. Customizing Line & Markers
[Link](x,y, color='red', linestyle='--', marker='o')
# color: 'red', 'g', '#FF0000'
# linestyle: '-', '--', '-.', ':'
# marker: 'o', 's', 'd', '^'
6. Subplots (Multiple plots in one figure)
[Link](2,1,1) # 2 rows, 1 col, 1st plot
[Link](x,y1)
[Link](2,1,2) # 2 rows, 1 col, 2nd plot
[Link](x,y2)
7. Figure & Axes (Object-Oriented)
fig, ax = [Link]() # Create figure and axes
[Link](x,y) # Plot on this axes
ax.set_title("Title") # Set title
ax.set_xlabel("X label") # X label
ax.set_ylabel("Y label") # Y label
8. Multiple Lines
[Link](x, y1, label="Line 1")
[Link](x, y2, label="Line 2")
[Link]()
9. Style & Grid
[Link]('ggplot') # Predefined style (ggplot, seaborn, etc.)
[Link](True) # Show grid
10. Saving Plots
[Link]("[Link]") # Save as PNG
[Link]("[Link]") # Save as PDF
[Link]("[Link]", dpi=300) # Save with resolution
11. Common Use Cases
- Line plots → Trends over time
- Scatter plots → Relationship between two variables
- Bar charts → Compare categories
- Histograms → Data distribution
- Pie charts → Proportions
- Subplots → Compare multiple plots together

You might also like