Skip to main content
TopMiniSite

Back to all posts

How to Create A 3D Plot In Matplotlib?

Published on
7 min read
How to Create A 3D Plot In Matplotlib? image

Best Tools for 3D Plotting in Matplotlib to Buy in December 2025

1 3D Printing Tools Kit,3D Printer Accessories, 3-Speed USB Rotary Tool with Bits & Deburring Tool for 3D Printing Burr, 3D Printer Model,Resin Model Engraving, Drilling, Carving, Polishing

3D Printing Tools Kit,3D Printer Accessories, 3-Speed USB Rotary Tool with Bits & Deburring Tool for 3D Printing Burr, 3D Printer Model,Resin Model Engraving, Drilling, Carving, Polishing

  • COMPLETE TOOLKIT FOR 3D MODELS: DEBURRING, DRILLING & POLISHING.

  • DURABLE ALUMINUM HANDLE FOR THE DEBURRING TOOL ENSURES LONG-LASTING USE.

  • VERSATILE 3-SPEED ROTARY PEN; PERFECT FOR VARIOUS MATERIALS AND TASKS.

BUY & SAVE
$21.35 $24.98
Save 15%
3D Printing Tools Kit,3D Printer Accessories, 3-Speed USB Rotary Tool with Bits & Deburring Tool for 3D Printing Burr, 3D Printer Model,Resin Model Engraving, Drilling, Carving, Polishing
2 32 Piece 3D Print Tool Kit Includes Debur Tool, Cleaning, Finishing and Printing Tool,3D Print Accessories for Cleaning, Finishing and Printing 3D Prints

32 Piece 3D Print Tool Kit Includes Debur Tool, Cleaning, Finishing and Printing Tool,3D Print Accessories for Cleaning, Finishing and Printing 3D Prints

  • COMPLETE 32-PIECE KIT FOR ALL YOUR 3D PRINTING NEEDS, HASSLE-FREE.

  • CONVENIENT STORAGE KEEPS TOOLS ORGANIZED FOR EFFICIENT USE.

  • FAST CUSTOMER SUPPORT ENSURES YOUR SATISFACTION WITHIN 12 HOURS!

BUY & SAVE
$19.99 $20.99
Save 5%
32 Piece 3D Print Tool Kit Includes Debur Tool, Cleaning, Finishing and Printing Tool,3D Print Accessories for Cleaning, Finishing and Printing 3D Prints
3 Housolution 8.5Inch 3D 6-in-1 Carpenter Square (1/16" Precision), 0-90° Aluminum Alloy Carpenter Square, Woodworking Protractor Drawing Line, Miter Triangle Ruler High Precision Layout, Blue

Housolution 8.5Inch 3D 6-in-1 Carpenter Square (1/16" Precision), 0-90° Aluminum Alloy Carpenter Square, Woodworking Protractor Drawing Line, Miter Triangle Ruler High Precision Layout, Blue

  • EXTENDED 8.5-INCH RANGE FOR PRECISE MEASUREMENTS.
  • DURABLE ALUMINUM ALLOY FOR LONG-LASTING USE.
  • 14 ADJUSTABLE HOLES FOR QUICK ANGLE ADJUSTMENTS.
BUY & SAVE
$22.99
Housolution 8.5Inch 3D 6-in-1 Carpenter Square (1/16" Precision), 0-90° Aluminum Alloy Carpenter Square, Woodworking Protractor Drawing Line, Miter Triangle Ruler High Precision Layout, Blue
4 99 PCS 3D Printing Tool Kit, 3D Printer Accessories with Cleaning Needles, Carving Knives, Files, Pliers, Tweezers, Wrench Set, Brush, Cutting Mat, for 3D Print Removing, Cleaning, Finishing

99 PCS 3D Printing Tool Kit, 3D Printer Accessories with Cleaning Needles, Carving Knives, Files, Pliers, Tweezers, Wrench Set, Brush, Cutting Mat, for 3D Print Removing, Cleaning, Finishing

  • COMPLETE 99-PIECE SET: ALL ESSENTIAL TOOLS FOR 3D PRINTING IN ONE KIT!
  • DURABLE & ERGONOMIC: HIGH-QUALITY MATERIALS ENSURE LONG-LASTING PERFORMANCE.
  • PORTABLE & VERSATILE: EASY TO CARRY FOR ANY DIY PROJECT OR CRAFTING NEEDS.
BUY & SAVE
$26.99 $28.79
Save 6%
99 PCS 3D Printing Tool Kit, 3D Printer Accessories with Cleaning Needles, Carving Knives, Files, Pliers, Tweezers, Wrench Set, Brush, Cutting Mat, for 3D Print Removing, Cleaning, Finishing
5 Sovol 3D Printer Tools Kit, 36 PCS 3D Printer Accessories with Deburring Tool, Digital Caliper, Art Knife Set, Removal Tools, Cutters, Pliers and Tools Storage Bag for Smoothing, Finishing, Craving

Sovol 3D Printer Tools Kit, 36 PCS 3D Printer Accessories with Deburring Tool, Digital Caliper, Art Knife Set, Removal Tools, Cutters, Pliers and Tools Storage Bag for Smoothing, Finishing, Craving

  • COMPREHENSIVE 36-PIECE KIT FOR COMPLETE 3D PRINTING NEEDS!

  • EFFORTLESS POST-PROCESSING WITH PRECISION TOOLS FOR PERFECT PRINTS!

  • CONVENIENT STORAGE BAG KEEPS YOUR 3D TOOLS ORGANIZED AND HANDY!

BUY & SAVE
$21.84 $22.99
Save 5%
Sovol 3D Printer Tools Kit, 36 PCS 3D Printer Accessories with Deburring Tool, Digital Caliper, Art Knife Set, Removal Tools, Cutters, Pliers and Tools Storage Bag for Smoothing, Finishing, Craving
6 Housolution 8.5Inch 3D 6-in-1 Carpenter Square (1/16" Precision), 0-90° Aluminum Alloy Carpenter Square, Woodworking Protractor Drawing Line, Miter Triangle Ruler High Precision Layout, Red

Housolution 8.5Inch 3D 6-in-1 Carpenter Square (1/16" Precision), 0-90° Aluminum Alloy Carpenter Square, Woodworking Protractor Drawing Line, Miter Triangle Ruler High Precision Layout, Red

  • EXTENDED MEASURING RANGE: 8.5 X 7.6 X 10.55 INCHES FOR PRECISION.

  • 14 HOLES FOR ANGLES: QUICKLY PLOT 22.5° TO 75° WITH EASE.

  • DURABLE ALUMINUM BUILD: SCRATCH-RESISTANT AND PRECISION-ENGINEERED.

BUY & SAVE
$21.99
Housolution 8.5Inch 3D 6-in-1 Carpenter Square (1/16" Precision), 0-90° Aluminum Alloy Carpenter Square, Woodworking Protractor Drawing Line, Miter Triangle Ruler High Precision Layout, Red
7 Microworld 3D Metal Model Tools, 2Pcs/Set Mini Flat Nose Plier Nipper Tool with Comfort Grip Handle, Professional for DIY 3D Metal Puzzle Model Kit Jigsaw Assembling

Microworld 3D Metal Model Tools, 2Pcs/Set Mini Flat Nose Plier Nipper Tool with Comfort Grip Handle, Professional for DIY 3D Metal Puzzle Model Kit Jigsaw Assembling

  • PRECISION CUTTING: INDUCTION-HARDENED BLADES FOR LASTING SHARPNESS.
  • VERSATILE REACH: LONG NOSE DESIGN FOR HARD-TO-REACH AREAS.
  • COMFORT GRIP: ERGONOMIC HANDLES REDUCE FATIGUE FOR PROLONGED USE.
BUY & SAVE
$16.99
Microworld 3D Metal Model Tools, 2Pcs/Set Mini Flat Nose Plier Nipper Tool with Comfort Grip Handle, Professional for DIY 3D Metal Puzzle Model Kit Jigsaw Assembling
8 3D Printing 3D Print Clean-Up Utility Tool Kit– 3 Piece Precision Print Clean-Up Tool Set – Double Ended Support Removal Accessories for 3D Prints

3D Printing 3D Print Clean-Up Utility Tool Kit– 3 Piece Precision Print Clean-Up Tool Set – Double Ended Support Removal Accessories for 3D Prints

  • EASY CLEAN-UP: QUICKLY REMOVE SUPPORT MATERIAL FOR FLAWLESS PRINTS!

  • 3-PIECE TOOL KIT: SIX VERSATILE BLADES IN ONE COMPACT UTILITY KIT!

  • DURABLE DESIGN: PRECISION STAINLESS STEEL WITH COMFORTABLE WOOD HANDLES!

BUY & SAVE
$20.10
3D Printing 3D Print Clean-Up Utility Tool Kit– 3 Piece Precision Print Clean-Up Tool Set – Double Ended Support Removal Accessories for 3D Prints
9 3D Printing Tool Set with Wood Box – 3D Printer Tools Features a deburring Tool, Wire Cutter, Drill, and Scraper for Model cleanup, Surface Smoothing, and Precise Drilling.

3D Printing Tool Set with Wood Box – 3D Printer Tools Features a deburring Tool, Wire Cutter, Drill, and Scraper for Model cleanup, Surface Smoothing, and Precise Drilling.

  • ORGANIZED STORAGE: STURDY WOODEN CASE KEEPS TOOLS ACCESSIBLE & SECURE.

  • ALL-IN-ONE SET: TOOLS FOR CLEANING, FINISHING, AND PERFECTING 3D PRINTS.

  • PRO-GRADE QUALITY: EXPERT-APPROVED TOOLS ENSURE PRECISION AND DURABILITY.

BUY & SAVE
$49.99 $59.99
Save 17%
3D Printing Tool Set with Wood Box – 3D Printer Tools Features a deburring Tool, Wire Cutter, Drill, and Scraper for Model cleanup, Surface Smoothing, and Precise Drilling.
10 10 Pcs Metal DIY Model Kit Tools,3D Metal Puzzle Tool Set for Adults,Including Plier Bending Assist Tab Edge Cylinder Cone Shape Bending Assist Tools, Metallic Tweezers

10 Pcs Metal DIY Model Kit Tools,3D Metal Puzzle Tool Set for Adults,Including Plier Bending Assist Tab Edge Cylinder Cone Shape Bending Assist Tools, Metallic Tweezers

  • DURABLE STAINLESS STEEL TOOLS FOR EASY AND EFFICIENT METAL ASSEMBLY.
  • 10 PRACTICAL TOOLS DESIGNED FOR VERSATILE DIY METAL PUZZLE CRAFTING.
  • PERFECT GIFT SET FOR DIY LOVERS TO ENHANCE THEIR CRAFTING EXPERIENCE!
BUY & SAVE
$14.99 $15.99
Save 6%
10 Pcs Metal DIY Model Kit Tools,3D Metal Puzzle Tool Set for Adults,Including Plier Bending Assist Tab Edge Cylinder Cone Shape Bending Assist Tools, Metallic Tweezers
+
ONE MORE?

To create a 3D plot in Matplotlib, you can follow these steps:

  1. Import the necessary libraries:

import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D

  1. Create a figure and an axis:

fig = plt.figure() ax = fig.add_subplot(111, projection='3d')

  1. Define your data points for the x, y, and z axes:

x = [1, 2, 3, 4, 5] y = [6, 7, 8, 9, 10] z = [11, 12, 13, 14, 15]

  1. Plot the 3D data points:

ax.scatter(x, y, z, c='r', marker='o')

  1. Set labels for the x, y, and z axes:

ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z')

  1. Set the title for the plot:

ax.set_title('3D Scatter Plot')

  1. Show the plot:

plt.show()

This will create a 3D scatter plot with your data points, where each point is represented as a marker in the 3D space defined by the x, y, and z axes.

How to change the marker style in a Matplotlib plot?

To change the marker style in a Matplotlib plot, you can use the marker parameter when calling the plot() function. This parameter allows you to specify the marker style using a string code.

Here is an example:

import matplotlib.pyplot as plt

Sample data

x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10]

Creating a line plot

plt.plot(x, y, marker='o')

Customizing the plot

plt.xlabel('X') plt.ylabel('Y') plt.title('Marker Style')

Displaying the plot

plt.show()

In the above example, the marker='o' parameter sets the marker style to a circle shape. You can use other string codes to change the marker style to a different shape. Some commonly used marker styles include:

  • o - circle
  • s - square
  • D - diamond
  • * - star
  • . - point

You can find more marker styles in the Matplotlib documentation.

How to plot a surface plot in Matplotlib?

To plot a 3D surface plot in Matplotlib, you can use the plot_surface() function from the Axes3D module. This function takes three arguments - the X, Y, and Z coordinates of the points to be plotted on the surface.

Below is an example code to plot a surface plot in Matplotlib:

import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D

Generate some sample data for the surface plot

x = np.linspace(-5, 5, 100) y = np.linspace(-5, 5, 100) X, Y = np.meshgrid(x, y) Z = np.sin(np.sqrt(X**2 + Y**2))

Create a figure and a set of subplots

fig = plt.figure() ax = fig.add_subplot(111, projection='3d')

Plot the surface plot

ax.plot_surface(X, Y, Z, cmap='viridis')

Set labels and title

ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') ax.set_title('Surface Plot')

Show the plot

plt.show()

In this example, the X and Y coordinates are created using np.meshgrid() and the Z coordinates are calculated using a mathematical function. The surface plot is created using the plot_surface() function on the ax object.

You can customize the surface plot by changing the color map (cmap), adding a color bar, changing the viewing angle, etc.

How to customize the line style in a Matplotlib plot?

To customize the line style in a Matplotlib plot, you can use the linestyle parameter in the plot() function. There are different line styles available, such as solid, dashed, dotted, or a combination of those.

Here's an example of how to customize the line style in a Matplotlib plot:

import matplotlib.pyplot as plt

Sample data

x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10]

Create a plot

plt.plot(x, y, linestyle='--') # Using dashed line style

Customize the line style

plt.plot(x, y, linestyle='-.', linewidth=2) # Using dash-dot line style with linewidth 2

Show the plot

plt.show()

In this example, the first plot() function call uses a dashed line style (linestyle='--'), and the second plot() function call uses a dash-dot line style (linestyle='-') and a linewidth of 2 (linewidth=2).

You can experiment with different line styles and linewidth values to achieve your desired customization.

How to create a stacked bar plot using Matplotlib?

To create a stacked bar plot using Matplotlib, you can follow these steps:

  1. Import the necessary libraries:

import matplotlib.pyplot as plt import numpy as np

  1. Define the data for the bar plot. Create an array or list for each category of data you want to plot, and combine them into a 2D array using the np.vstack function:

data1 = np.array([1, 2, 3, 4, 5]) data2 = np.array([2, 3, 4, 5, 6]) data3 = np.array([3, 4, 5, 6, 7])

data = np.vstack([data1, data2, data3])

  1. Create the figure and axes objects:

fig, ax = plt.subplots()

  1. Use the ax.bar function to create the stacked bar plot. Specify the positions, widths, and heights of the bars:

ax.bar(range(len(data[0])), data[0], label='Data 1') ax.bar(range(len(data[0])), data[1], bottom=data[0], label='Data 2') ax.bar(range(len(data[0])), data[2], bottom=data[0]+data[1], label='Data 3')

  1. Set the labels, title, and legend of the plot:

ax.set_xlabel('X-axis') ax.set_ylabel('Y-axis') ax.set_title('Stacked Bar Plot') ax.legend()

  1. Finally, show the plot:

plt.show()

Putting it all together, the complete code for creating a stacked bar plot using Matplotlib would look like this:

import matplotlib.pyplot as plt import numpy as np

data1 = np.array([1, 2, 3, 4, 5]) data2 = np.array([2, 3, 4, 5, 6]) data3 = np.array([3, 4, 5, 6, 7])

data = np.vstack([data1, data2, data3])

fig, ax = plt.subplots() ax.bar(range(len(data[0])), data[0], label='Data 1') ax.bar(range(len(data[0])), data[1], bottom=data[0], label='Data 2') ax.bar(range(len(data[0])), data[2], bottom=data[0]+data[1], label='Data 3')

ax.set_xlabel('X-axis') ax.set_ylabel('Y-axis') ax.set_title('Stacked Bar Plot') ax.legend()

plt.show()

This code will create a stacked bar plot with three categories of data. Each category will be represented by a different color, and the bars will be stacked one above the other.

How to create subplots in Matplotlib?

To create subplots in Matplotlib, you can make use of the subplot() function. Here's a step-by-step approach:

  1. Import the necessary libraries:

import matplotlib.pyplot as plt

  1. Define the number and arrangement of subplots. This can be done using the subplot() function, which takes three arguments: the total number of rows, the total number of columns, and the index of the current subplot.

plt.subplot(rows, columns, index)

For example, to create a grid of 2 rows and 2 columns with a specific index:

plt.subplot(2, 2, 1) # 1st plot plt.subplot(2, 2, 2) # 2nd plot plt.subplot(2, 2, 3) # 3rd plot plt.subplot(2, 2, 4) # 4th plot

  1. Plot the data in each subplot using regular Matplotlib plotting functions like plot(), bar(), scatter(), etc.

plt.subplot(2, 2, 1) plt.plot(x1, y1) plt.title('Subplot 1')

plt.subplot(2, 2, 2) plt.scatter(x2, y2) plt.title('Subplot 2')

...

  1. Add any necessary global adjustments like figure titles or labels.

plt.suptitle('Main Title')

plt.subplot(2, 2, 1) plt.ylabel('Y-axis')

...

  1. Finally, display the plot using plt.show().

plt.show()

By following these steps, you can create multiple subplots within a single Matplotlib figure.

How to plot 3D contours in Matplotlib?

To plot 3D contours in Matplotlib, you can use the contour function from the Axes3D module. Here's a step-by-step guide:

  1. Import the necessary modules:

import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D

  1. Create a figure and an axes object:

fig = plt.figure() ax = fig.add_subplot(111, projection='3d')

  1. Define the x, y, and z values for your data:

x = np.linspace(-5, 5, 100) y = np.linspace(-5, 5, 100) X, Y = np.meshgrid(x, y) Z = np.sin(np.sqrt(X**2 + Y**2))

  1. Plot the 3D contour plot using the contour function:

ax.contour3D(X, Y, Z, cmap='viridis')

  1. Customize the plot if needed:

ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') ax.set_title('3D Contour Plot')

  1. Show the plot:

plt.show()

Putting it all together, here's an example that shows how to plot a 3D contour plot for a function z = sin(sqrt(x^2 + y^2)):

import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure() ax = fig.add_subplot(111, projection='3d')

x = np.linspace(-5, 5, 100) y = np.linspace(-5, 5, 100) X, Y = np.meshgrid(x, y) Z = np.sin(np.sqrt(X**2 + Y**2))

ax.contour3D(X, Y, Z, cmap='viridis')

ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') ax.set_title('3D Contour Plot')

plt.show()

This will generate a 3D plot of the function with contours representing the height of the function in the z-axis.