PGFPlots for Beginners
A step-by-step guide to creating your first plots with PGFPlots in LaTeX.
The Basic Structure
Every PGFPlots graphic follows this structure:
Your First Plot
Let's plot a simple function:
This creates a basic plot of x² with automatic axis scaling.
Adding Labels and Title
Styling Your Plot
Plotting Data Points
Plot specific coordinates instead of functions:
Line Styles and Markers
Setting Axis Limits
Multiple Plots
Tip: Use domain=-5:5 in the axis options or addplot to specify the x-range for function plots.
Complete Beginner Example
Common Beginner Mistakes
- Missing compat setting: Always include
\pgfplotsset{compat=1.18} - Forgetting tikzpicture: The axis environment must be inside tikzpicture.
- Incorrect function syntax: Use
sin(deg(x))notsin(x)for trig functions. - Missing semicolons: Each
\addplotcommand ends with a semicolon.
Next Steps
Continue learning PGFPlots:
- Basic Setup - Configuration options
- Line Plots - Detailed line plot tutorial
- Scatter Plots - Visualize data points
PGFPlots for Beginners
A step-by-step guide to creating your first plots with PGFPlots in LaTeX.
The Basic Structure
Every PGFPlots graphic follows this structure:
Your First Plot
Let's plot a simple function:
This creates a basic plot of x² with automatic axis scaling.
Adding Labels and Title
Styling Your Plot
Plotting Data Points
Plot specific coordinates instead of functions:
Line Styles and Markers
Setting Axis Limits
Multiple Plots
Tip: Use domain=-5:5 in the axis options or addplot to specify the x-range for function plots.
Complete Beginner Example
Common Beginner Mistakes
- Missing compat setting: Always include
\pgfplotsset{compat=1.18} - Forgetting tikzpicture: The axis environment must be inside tikzpicture.
- Incorrect function syntax: Use
sin(deg(x))notsin(x)for trig functions. - Missing semicolons: Each
\addplotcommand ends with a semicolon.
Next Steps
Continue learning PGFPlots:
- Basic Setup - Configuration options
- Line Plots - Detailed line plot tutorial
- Scatter Plots - Visualize data points
