Skip to main content
TopMiniSite

Back to all posts

How to Plot A Graph With Matplotlib?

Published on
4 min read
How to Plot A Graph With Matplotlib? image

Best Graph Plotting Tools to Buy in October 2025

1 Mr. Pen Metal Geometry Kit - 4Pack Set Square, Protractor, Aluminum Ruler, Drafting Triangles

Mr. Pen Metal Geometry Kit - 4Pack Set Square, Protractor, Aluminum Ruler, Drafting Triangles

  • DURABLE ALUMINUM ALLOY ENSURES LASTING QUALITY AND PRECISION.
  • VERSATILE SET IDEAL FOR STUDENTS, ARCHITECTS, AND ENGINEERS ALIKE.
  • LIGHTWEIGHT DESIGN FOR EASY HANDLING AND ACCURATE MEASUREMENTS.
BUY & SAVE
$7.99
Mr. Pen Metal Geometry Kit - 4Pack Set Square, Protractor, Aluminum Ruler, Drafting Triangles
2 Mr. Pen- Graph Paper Sticky Notes, 6 Pads, 3x3 Inch, Bright Colors, Graph Sticky Notes

Mr. Pen- Graph Paper Sticky Notes, 6 Pads, 3x3 Inch, Bright Colors, Graph Sticky Notes

  • STIMULATE CREATIVITY WITH 6 UNIQUE GRAPH DESIGNS FOR ORGANIZATION.

  • COLOR-CODED OPTIONS ENHANCE QUICK INFORMATION RETRIEVAL & SORTING!

  • SUPERIOR ADHESIVE STICKS SECURELY, EASILY REMOVABLE WITHOUT RESIDUE.

BUY & SAVE
$6.99
Mr. Pen- Graph Paper Sticky Notes, 6 Pads, 3x3 Inch, Bright Colors, Graph Sticky Notes
3 Mead Spiral Notebook, 1 Subject, Graph Ruled Paper, 7-1/2" x 10-1/2", 100 Sheets, Green (05676AC5)

Mead Spiral Notebook, 1 Subject, Graph Ruled Paper, 7-1/2" x 10-1/2", 100 Sheets, Green (05676AC5)

  • 100 GRAPH RULED SHEETS PERFECT FOR PLOTTING AND DESIGNING.
  • DURABLE COVER WITH WRITABLE LABEL FOR EASY ORGANIZATION.
  • CONVENIENT 3-HOLE PUNCH FITS STANDARD BINDERS.
BUY & SAVE
$3.70 $5.29
Save 30%
Mead Spiral Notebook, 1 Subject, Graph Ruled Paper, 7-1/2" x 10-1/2", 100 Sheets, Green (05676AC5)
4 Nicpro 20PCS Professional Geometry Set with Case, Drafting Tools with Protractor and Compass, Metal Rulers, Triangles, Pens, Pencils, Drawing Supplies, Drafting Kit for Architect Engineer Students

Nicpro 20PCS Professional Geometry Set with Case, Drafting Tools with Protractor and Compass, Metal Rulers, Triangles, Pens, Pencils, Drawing Supplies, Drafting Kit for Architect Engineer Students

  • PREMIUM STAINLESS STEEL COMPASSES FOR PRECISE, ADJUSTABLE CIRCLES.
  • ALL-IN-ONE GEOMETRY SET PERFECT FOR SCHOOL, ART, AND ENGINEERING TASKS.
  • DURABLE, PORTABLE STORAGE BOX KEEPS TOOLS ORGANIZED AND ACCESSIBLE.
BUY & SAVE
$21.99
Nicpro 20PCS Professional Geometry Set with Case, Drafting Tools with Protractor and Compass, Metal Rulers, Triangles, Pens, Pencils, Drawing Supplies, Drafting Kit for Architect Engineer Students
5 Graph Paper Sticky Notes Set, 6 Pastel Colors, 4x4 Inch Grid Pads, 20x20 Squares, 50 Sheets per Pad, 4mm Grid Lines, Math Coordinate Plane Notes for School (White)

Graph Paper Sticky Notes Set, 6 Pastel Colors, 4x4 Inch Grid Pads, 20x20 Squares, 50 Sheets per Pad, 4mm Grid Lines, Math Coordinate Plane Notes for School (White)

  • COMPREHENSIVE SET: 300 GRID NOTEPADS, PERFECT FOR MATH AND PLANNING!
  • PRECISE GRID DESIGN: 20X20 SQUARES ENSURE ACCURATE PLOTTING EVERY TIME.
  • COLOR VARIETY: SIX PASTEL SHADES SIMPLIFY PROJECT ORGANIZATION EFFORTLESSLY.
BUY & SAVE
$9.99 $11.99
Save 17%
Graph Paper Sticky Notes Set, 6 Pastel Colors, 4x4 Inch Grid Pads, 20x20 Squares, 50 Sheets per Pad, 4mm Grid Lines, Math Coordinate Plane Notes for School (White)
6 Graph Paper Pad 22"x17", 50 Sheets, 1/4 Inch Grid, 80 GSM, Engineering Drafting Paper for Designers, Blueprint Sketching, Grid-Based Graphing for Architecture, School, Office

Graph Paper Pad 22"x17", 50 Sheets, 1/4 Inch Grid, 80 GSM, Engineering Drafting Paper for Designers, Blueprint Sketching, Grid-Based Graphing for Architecture, School, Office

  • VERSATILE USAGE: TAILORED FOR ARCHITECTS; EXCELS IN PRECISION DRAFTING.
  • CONVENIENT FORMAT: LOOSE LEAF OPTIONS FOR EASY ORGANIZATION AND FLEXIBILITY.
  • PROFESSIONAL FINISH: HIGH-QUALITY PAPER ENHANCES YOUR PROJECTS' PRESENTATIONS.
BUY & SAVE
$29.99
Graph Paper Pad 22"x17", 50 Sheets, 1/4 Inch Grid, 80 GSM, Engineering Drafting Paper for Designers, Blueprint Sketching, Grid-Based Graphing for Architecture, School, Office
7 Mr. Pen- Graph Paper, 2 Pack of 22 Sheets, 17"x11", 4x4 (4 Squares per inch), Graphing Paper, Grid Paper Pad, Math Graph Paper Pad, Drafting Paper, Computation Pads, Large Graph Paper

Mr. Pen- Graph Paper, 2 Pack of 22 Sheets, 17"x11", 4x4 (4 Squares per inch), Graphing Paper, Grid Paper Pad, Math Graph Paper Pad, Drafting Paper, Computation Pads, Large Graph Paper

  • PACK OF 2 WITH 44 TOTAL SHEETS FOR ALL YOUR GRAPHING NEEDS.

  • 4X4 GRID OFFERS DETAIL FOR PRECISE DIAGRAMS AND CALCULATIONS.

  • STURDY, BLEED-RESISTANT PAPER KEEPS YOUR WORK CLEAN AND LEGIBLE.

BUY & SAVE
$11.99
Mr. Pen- Graph Paper, 2 Pack of 22 Sheets, 17"x11", 4x4 (4 Squares per inch), Graphing Paper, Grid Paper Pad, Math Graph Paper Pad, Drafting Paper, Computation Pads, Large Graph Paper
+
ONE MORE?

To plot a graph with matplotlib, you first need to import the matplotlib library using the following command:

import matplotlib.pyplot as plt

Then you can create a figure and axes using the subplots function:

fig, ax = plt.subplots()

Next, you can plot your data on the axes using the plot function. For example, to plot a line graph, you can use:

ax.plot(x_data, y_data)

You can customize the graph by adding labels to the axes, a title, and a legend by using functions such as xlabel, ylabel, title, and legend.

Finally, you can show the graph using the show function:

plt.show()

This will display the plotted graph in a window or within a Jupyter notebook if you are using one.

What is a legend in matplotlib?

In matplotlib, a legend is a box or area on a plot that provides an explanation of the symbols, colors, and line styles used to represent different data sets or categories in the plot. Legends are helpful for making plots easier to understand and interpret, especially when there are multiple elements on the plot. Legends can be placed in different locations on the plot, and can be customized in terms of font size, style, and position.

How to display multiple plots in a single figure with matplotlib?

To display multiple plots in a single figure with matplotlib, you can use the subplot() function. The subplot() function takes three arguments - the number of rows, the number of columns, and the index of the subplot you want to create.

Here is an example code snippet to display multiple plots in a single figure:

import matplotlib.pyplot as plt

Create some data for the plots

x = [1, 2, 3, 4, 5] y1 = [1, 4, 9, 16, 25] y2 = [1, 2, 3, 4, 5]

Create a figure and set the size

plt.figure(figsize=(10, 5))

Create the first subplot

plt.subplot(1, 2, 1) plt.plot(x, y1) plt.title('Plot 1')

Create the second subplot

plt.subplot(1, 2, 2) plt.plot(x, y2) plt.title('Plot 2')

Display the plots

plt.show()

This code will create a single figure with two subplots, each displaying a different plot. You can adjust the number of rows and columns in the subplot() function to create more subplots in a single figure.

How to save a matplotlib plot as an image file?

To save a matplotlib plot as an image file, you can use the savefig() function provided by matplotlib. Here is an example code snippet showing how to save a plot as a PNG image file:

import matplotlib.pyplot as plt

Create a sample plot

plt.plot([1, 2, 3, 4], [1, 4, 9, 16])

Save the plot as a PNG image file

plt.savefig('plot.png')

Display the plot

plt.show()

In this example, the savefig() function is used to save the plot as a PNG image file named plot.png. You can specify the file format by providing the file extension in the filename. You can also specify the dpi (dots per inch) of the image by passing the dpi parameter to the savefig() function.

How to customize the tick marks on an axis in a matplotlib plot?

You can customize the tick marks on an axis in a matplotlib plot by using the xticks() and yticks() functions. These functions allow you to specify the positions and labels of the tick marks on the x-axis and y-axis respectively.

Here is an example of how to customize the tick marks on the x-axis of a matplotlib plot:

import matplotlib.pyplot as plt import numpy as np

Generate some data

x = np.linspace(0, 10, 100) y = np.sin(x)

Create the plot

plt.plot(x, y)

Customize the tick marks on the x-axis

plt.xticks([0, 2, 4, 6, 8, 10], ['A', 'B', 'C', 'D', 'E', 'F'])

Show the plot

plt.show()

In this example, we use the xticks() function to specify the positions of the tick marks on the x-axis at 0, 2, 4, 6, 8, and 10, and we set the labels for these tick marks as 'A', 'B', 'C', 'D', 'E', and 'F' respectively.

You can also customize the appearance of the tick marks by using additional arguments in the xticks() and yticks() functions, such as setting the font size, font color, rotation angle, and alignment of the tick labels.

What is the purpose of the plt.xlabel() and plt.ylabel() functions in matplotlib?

The purpose of the plt.xlabel() and plt.ylabel() functions in matplotlib is to set the labels for the x-axis and y-axis of a plot, respectively. These functions allow the user to provide names or descriptions for the axes of a plot, making it easier to interpret the data being visualized.