Live Jobs
NEWSoftware Engineer - Automation Tester@UplersNEWSenior Embedded Systems Software Engineer@Google India Pvt LtdNEWManager, Software Engineering - IOS - Player Team, Bangalore@Warner Bros. DiscoveryNEWSenior Software Engineer - Java@ClarivateNEWSoftware Engineer - Automation Tester@UplersSoftware Developer 2, Python Backend Developer@Kinaxis Inc.Software Developer Intern@Mexilet Technologies Private LimitedFull-Stack Software Engineer Intern - Remote@UplersSoftware Engineer, AIML - Fixed Term Contract (6 months)@NatWest GroupNEWSoftware Engineer - Automation Tester@UplersNEWSenior Embedded Systems Software Engineer@Google India Pvt LtdNEWManager, Software Engineering - IOS - Player Team, Bangalore@Warner Bros. DiscoveryNEWSenior Software Engineer - Java@ClarivateNEWSoftware Engineer - Automation Tester@UplersSoftware Developer 2, Python Backend Developer@Kinaxis Inc.Software Developer Intern@Mexilet Technologies Private LimitedFull-Stack Software Engineer Intern - Remote@UplersSoftware Engineer, AIML - Fixed Term Contract (6 months)@NatWest GroupNEWSoftware Engineer - Automation Tester@UplersNEWSenior Embedded Systems Software Engineer@Google India Pvt LtdNEWManager, Software Engineering - IOS - Player Team, Bangalore@Warner Bros. DiscoveryNEWSenior Software Engineer - Java@ClarivateNEWSoftware Engineer - Automation Tester@UplersSoftware Developer 2, Python Backend Developer@Kinaxis Inc.Software Developer Intern@Mexilet Technologies Private LimitedFull-Stack Software Engineer Intern - Remote@UplersSoftware Engineer, AIML - Fixed Term Contract (6 months)@NatWest Group

Matplotlib PlottingCheat Sheet

Master data visualization with comprehensive Matplotlib commands and plotting techniques

Data Visualization
Plot Customization
Performance Tips

1
Plot Creation & Setup

Import Matplotlib

Standard way to import matplotlib for plotting

import matplotlib.pyplot as plt
basicplottingsetup
Example:
import matplotlib.pyplot as plt import numpy as np
Quick Tip:
Always import as plt for convention and shorter syntax
✅ Best Practice:
DO: Import numpy alongside for data generation, use consistent import aliases, set backend early if needed for non-interactive environments
❌ Common Mistake:
DON'T: Import entire matplotlib module (memory intensive), use non-standard aliases that confuse collaborators, forget to import numpy for data manipulation

Create Figure

Create a new figure with specified size

plt.figure(figsize=(width, height))
basicplottingsetup
Example:
plt.figure(figsize=(10, 6)) # 10 inches wide, 6 inches tall
Quick Tip:
Set figsize early to avoid cramped plots
✅ Best Practice:
DO: Set figsize based on output medium (screen vs print), use dpi parameter for high-resolution outputs, create figure before plotting for better control
❌ Common Mistake:
DON'T: Use default figure size for all plots, forget to close figures in loops (memory leaks), create figures without considering aspect ratio

Line Plot

Create a line plot with x and y data

plt.plot(x, y, options)
basicplottingline-charts
Example:
x = [1, 2, 3, 4] y = [1, 4, 2, 3] plt.plot(x, y, 'b-o') # Blue line with circles
Quick Tip:
Use format strings like 'r-' for red line, 'bo' for blue circles
✅ Best Practice:
DO: Use meaningful labels and legends, choose appropriate line styles and markers, set linewidth for better visibility
❌ Common Mistake:
DON'T: Plot too many lines without distinguishing colors/styles, use default markers for overlapping data points, forget to add axis labels and titles

Scatter Plot

Create a scatter plot to show relationship between variables

plt.scatter(x, y, options)
basicplottingscatter
Example:
plt.scatter(x, y, c='red', alpha=0.7, s=50) # Red dots, 70% opacity
Quick Tip:
Use alpha for transparency, s for size, c for color
✅ Best Practice:
DO: Use alpha for overlapping points, vary point sizes meaningfully with s parameter, choose colormap that's accessible to colorblind users
❌ Common Mistake:
DON'T: Use scatter plots with too many points without alpha, ignore outliers that may indicate data issues, use default point size for all datasets regardless of scale

Bar Plot

Create vertical bar chart

plt.bar(x, height, options)
basicplottingbar-charts
Example:
categories = ['A', 'B', 'C'] values = [3, 7, 5] plt.bar(categories, values, color='skyblue')
Quick Tip:
Use plt.barh() for horizontal bars
✅ Best Practice:
DO: Sort bars by value for better readability, use consistent colors or meaningful color coding, add value labels on bars for clarity
❌ Common Mistake:
DON'T: Use too many bars without grouping, choose colors that are hard to distinguish, forget to rotate x-axis labels when they overlap

Histogram

Create histogram to show data distribution

plt.hist(data, bins=n, options)
basicplottingdistribution
Example:
data = np.random.normal(0, 1, 1000) plt.hist(data, bins=30, alpha=0.7, color='green')
Quick Tip:
Experiment with bin count - too few or too many can hide patterns
✅ Best Practice:
DO: Choose appropriate bin count (sqrt(n) or Sturges' rule), use alpha for transparency with overlapping histograms, add density=True for probability density
❌ Common Mistake:
DON'T: Use default bins for all data sizes, ignore outliers that may skew the distribution, overlay histograms without transparency

Display Plot

Display the current figure

plt.show()
basicplottingdisplay
Example:
plt.plot([1, 2, 3], [1, 4, 2]) plt.show() # Shows the plot
Quick Tip:
Call plt.show() at the end to display your plot
✅ Best Practice:
DO: Call plt.show() at the end of your plotting code, use plt.show(block=False) for non-blocking display, close figures after showing to free memory
❌ Common Mistake:
DON'T: Call plt.show() multiple times in scripts (can cause issues), forget to call plt.show() in scripts (plots won't display), use in loops without closing figures

2
Plot Customization

Add Title

Add title to the plot

plt.title("Title Text", options)
basiccustomizationlabels
Example:
plt.title("Sales Data 2024", fontsize=16, fontweight='bold')
Quick Tip:
Use fontsize and fontweight to make titles stand out
✅ Best Practice:
DO: Use descriptive titles that explain what the plot shows, set appropriate font size for the output medium, use fontweight="bold" for emphasis
❌ Common Mistake:
DON'T: Use generic titles like "Plot" or "Graph", make titles too long for the plot size, forget to include units or time periods when relevant

Axis Labels

Add labels to x and y axes

plt.xlabel("X Label") / plt.ylabel("Y Label")
basiccustomizationlabels
Example:
plt.xlabel("Time (hours)", fontsize=12) plt.ylabel("Temperature (°C)", fontsize=12)
Quick Tip:
Always label your axes with units when applicable
✅ Best Practice:
DO: Include units in labels, use descriptive labels, set appropriate fontsize for readability, use LaTeX for mathematical expressions
❌ Common Mistake:
DON'T: Use generic labels like "X" or "Y", forget units when applicable, use labels that are too long for the plot size, ignore special characters in labels

Add Legend

Add legend to identify different data series

plt.legend(labels, options)
basiccustomizationlegend
Example:
plt.plot(x, y1, label='Series 1') plt.plot(x, y2, label='Series 2') plt.legend()
Quick Tip:
Use label parameter in plot functions, then call plt.legend()
✅ Best Practice:
DO: Use descriptive legend labels, position legend to avoid data overlap, use bbox_to_anchor for precise positioning, limit legend entries to <8 for clarity
❌ Common Mistake:
DON'T: Create legends with too many entries, place legends over important data, use generic labels like "Line 1", forget to call plt.legend() after setting labels

Add Grid

Add grid lines to make reading values easier

plt.grid(True, options)
basiccustomizationreadability
Example:
plt.grid(True, alpha=0.3, linestyle='--')
Quick Tip:
Use alpha to make grid subtle, linestyle for different patterns
✅ Best Practice:
DO: Use alpha<0.5 for subtle grids, choose appropriate linestyle (-- or :), enable grid for data-heavy plots, use which="both" for major and minor grids
❌ Common Mistake:
DON'T: Use opaque grids that overwhelm data, add grids to every plot regardless of need, use default grid settings without customization, ignore minor grids when helpful

Colors & Styles

Customize colors using names, letters, or hex codes

color="name" / c="letter" / color="#hex"
basiccustomizationstyling
Example:
plt.plot(x, y, color='red') # or c='r' or color='#FF0000'
Quick Tip:
Use hex codes for exact colors, named colors for simplicity
✅ Best Practice:
DO: Use colorblind-friendly palettes, specify colors consistently across related plots, use hex codes for brand colors, test color combinations for accessibility
❌ Common Mistake:
DON'T: Use default colors for all plots, ignore colorblind accessibility, use too many similar colors, choose colors that don't print well in grayscale

Set Axis Limits

Set the range of values shown on axes

plt.xlim(min, max) / plt.ylim(min, max)
basiccustomizationscaling
Example:
plt.xlim(0, 10) # X-axis from 0 to 10 plt.ylim(-5, 15) # Y-axis from -5 to 15
Quick Tip:
Use to zoom in on specific data ranges or ensure consistent scales
✅ Best Practice:
DO: Set limits to focus on important data ranges, use consistent limits across related plots, leave some padding around data, consider data distribution when setting limits
❌ Common Mistake:
DON'T: Cut off important data points, use limits that are too tight (no padding), ignore outliers when setting limits, use different scales for comparable plots