Matplotlib.pyplot.setp() function in Python
Last Updated :
10 Jul, 2025
matplotlib.pyplot.setp() function sets properties on an artist or a list of artists such as lines, texts, or patches in Matplotlib. It allows you to modify multiple properties at once, such as color, linewidth, linestyle, font size and more, after the plot elements have been created.
Example:
Python
import matplotlib.pyplot as plt
line, = plt.plot([1, 2, 3], [4, 5, 6])
plt.setp(line, color='red', linewidth=2, linestyle='--')
plt.show()
Output
Red dashed lineExplanation: plt.setp() changes the line color to red, width to 2 and style to dashed, updating the plot to show a thicker red dashed line.
Syntax
matplotlib.pyplot.setp(obj, *args, **kwargs)
Parameters:
- obj: A single Matplotlib artist or a list of artists to modify.
- *args: Property-value pairs provided in sequence (e.g., 'color', 'red').
- **kwargs: Property-value pairs provided as keyword arguments (e.g., color='red').
Returns: A list of property values that were set.
Examples
Example 1: Setting properties using keyword arguments
Python
import matplotlib.pyplot as plt
lines = plt.plot([1, 2, 3], [3, 6, 9])
plt.setp(lines, color='green', linewidth=3)
plt.show()
Output
Thick green lineExplanation: plt.setp() changes the line color to green and width to 3, updating the plot to show a thicker green solid line.
Example 2: Setting properties using property-value pairs as args
Python
import matplotlib.pyplot as plt
lines = plt.plot([1, 2, 3], [1, 4, 9])
plt.setp(lines, 'linestyle', ':', 'marker', 'o', 'markersize', 8)
plt.show()
Output
Dotted line with circlesExplanation: plt.setp() sets a dotted line (':'), adds circle markers ('o') and increases marker size to 8, making the plot more visually distinct.
Example 3: Changing text properties
Python
import matplotlib.pyplot as plt
text = plt.text(0.5, 0.5, 'Sample Text')
plt.setp(text, color='blue', fontsize=14, fontweight='bold')
plt.show()
Output
Bold blue textExplanation: plt.setp() sets the text color to blue, size to 14 and weight to bold, displaying "Sample Text" in bold blue at (0.5, 0.5).
Related article: Matplotlib
Similar Reads
Matplotlib.pyplot.suptitle() function in Python Matplotlib is a library in Python and it is a mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. matplotlib.pyplot.suptitle() Function The suptitle() function in pyplot module of the matplotlib library is used to
3 min read
Matplotlib.pyplot.pcolor() function in Python Matplotlib is the well-known Python package used in data visualization. Numpy is the numerical mathematics extension of Matplotlib. Matplotlib is capable of producing high-quality graphs, charts, and figures. Matplotlib produces object-oriented API for embedding plots into projects using GUI toolkit
2 min read
Matplotlib.pyplot.set_cmap() in Python Matplotlib.pyplot.set_cmap() is a function in matplotlib that is used to set the default colormap for the current image or plot. A color map is a mapping from data values to colors, and it is essential in visualizing data through color variations, particularly in heatmaps, contour plots, and other t
3 min read
Matplotlib.pyplot.figimage() function in Python Matplotlib is a widely used library in Python for plotting various graphs, as it provides very efficient ways and easy to understand methods for complex plots also. pyplot is a collection of command style functions that make matplotlib work like MATLAB. figimage() function matplotlib.pyplot.figimage
2 min read
Matplotlib.pyplot.autumn() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot,
2 min read
Matplotlib.pyplot.gci() in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot,
2 min read