VOOZH about

URL: https://www.geeksforgeeks.org/python/matplotlib-axes-axes-set-in-python/

⇱ Matplotlib.axes.Axes.set() in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Matplotlib.axes.Axes.set() in Python

Last Updated : 12 Jul, 2025

Axes.set() function in Matplotlib is used to set multiple Axes properties at once using keyword arguments (**kwargs). This is a convenient way to configure an Axes object with labels, limits, title and more, all in one call. It's key features include:

  • Acts as a batch property setter for Axes.
  • Uses keyword arguments to set multiple properties like title, labels, axis limits, etc.
  • Commonly used in plots to quickly configure appearance.
  • Modifies the Axes object in-place.

Example:

Output

👁 Output
Using Matplotlib.axes().Axes.set()

Explanation:

  • fig, ax = plt.subplots() creates the figure and plotting area.
  • ax.plot(...) draws the line plot with given x and y data.
  • ax.set(...) sets multiple properties like axis labels and title in one call for cleaner code.

Syntax

Axes.set(self, **kwargs)

Parameters: **kwargs is a keyword arguments representing property names and their values (e.g., xlabel, ylabel, title, xlim, ylim, etc.)

Returns: The modified Axes object.

Examples of matplotlib.axes.Axes.set()

Example 1: In this example, we plot a sine wave and use the ax.set() method to configure multiple properties of the Axes object in one call.

Output

👁 Output
Using Matplotlib.axes().Axes.set()

Explanation: This code calculates a sine wave scaled by 0.4 and shifted by 1 to create oscillations around 1, then initializes a figure and axes for plotting. It plots the sine wave against time and uses ax.set() to simultaneously set axis labels, axis limits and the plot title.

Example 2 : In this example, we create a scatter plot with randomly generated data points using NumPy and Matplotlib.

Output

👁 Output
Using Matplotlib.axes().Axes.set()

Explanation: This code initializes a figure and axes for plotting, then generates 200 random points for x and y coordinates, along with sizes and colors for each scatter point. It scales the sizes, plots the scatter points and uses ax.set() to set axis labels and limit the displayed range.


Comment
Article Tags: