A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/matplotlib-pyplot-axes-in-python/ below:

Matplotlib.pyplot.axes() in Python - GeeksforGeeks

Matplotlib.pyplot.axes() in Python

Last Updated : 12 Jul, 2025

axes() method in Matplotlib is used to create a new Axes instance (i.e., a plot area) within a figure. This allows you to specify the location and size of the plot within the figure, providing more control over subplot layout compared to plt.subplot(). It's key features include:

Example:

Python
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = plt.axes([0.1, 0.1, 0.8, 0.8])

x = np.linspace(0, 10, 100)
y = np.sin(x)
ax.plot(x, y)
plt.show()

Output

Using Matplotlib.pyplot.axes()

Explanation:

Syntax

matplotlib.pyplot.axes(*args, **kwargs)

Parameters: The parameters can be passed in different ways:

1. Positional Argument rect: A list or tuple of 4 floats [left, bottom, width, height] and defines the position and size of the axes as fractions of the figure width and height, all values between 0 and 1.

2. Keyword Arguments (kwargs): A dictionary of additional keyword arguments to customize the Axes object. Some common keyword arguments include:

Returns: (Axes) An instance of matplotlib.axes.Axes (or a subclass like Axes3D) .The newly created Axes object which can be used to plot data and customize the plot.

Examples

Example 1: In this example we are creating multiple axes in one figure.

Python
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax1 = plt.axes([0.1, 0.1, 0.35, 0.8])  # Left small axes
ax2 = plt.axes([0.55, 0.1, 0.35, 0.8]) # Right small axes

x = np.linspace(0, 10, 100)
ax1.plot(x, np.sin(x))
ax2.plot(x, np.cos(x))

plt.show()

Output

Using Matplotlib.pyplot.axes()

Explanation:

Example 2: In this example, we are creating 3d axes

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

fig = plt.figure()
ax = plt.axes([0.1, 0.1, 0.8, 0.8], 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.plot_surface(X, Y, Z, cmap='viridis')
plt.show()

Output

Using Matplotlib.pyplot.axes()

Explanation:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4