Matplotlib.patches.PathPatch in Python - GeeksforGeeks (2025)

Last Updated : 27 Apr, 2020

Summarize

Comments

Improve

Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack.

matplotlib.patches.PathPatch

The matplotlib.patches.PathPatch class used to draw general polycurve path patch.

Syntax: class matplotlib.patches.PathPatch(path, **kwargs)

Parameter:

  • path: path is a matplotlib.path.Path object.

The below tables gives the list of valid kwargs arguments:

PROPERTY DESCRIPTION
agg_filter a filter function that takes a (m, n, 3) float array and a dpi value that returns a (m, n, 3) array
alpha float or None
animated bool
antialiased or aa unknown
capstyle {‘butt’, ’round’, ‘projecting’}
clip_box Bbox
clip_on bool
clip_path [(Path, Transform)|Patch|None]
color color or sequence of rgba tuples
contains callable
edgecolor or ec or edgecolors color or None or ‘auto’
facecolor or fc or facecolors color or None
figure figure
fill bool
gid str
hatch {‘/’, ‘\’, ‘|’, ‘-‘, ‘+’, ‘x’, ‘o’, ‘O’, ‘.’, ‘*’}
in_layout bool
joinstyle {‘miter’, ’round’, ‘bevel’}
linestyle or ls {‘-‘, ‘–‘, ‘-.’, ‘:’, ”, (offset, on-off-seq), …}
linewidth or linewidths or lw float or None
path_effects AbstractPathEffect
picker None or bool or float or callable
path_effects AbstractPathEffect
picker float or callable[[Artist, Event], Tuple[bool, dict]]
rasterized bool or None
sketch_params (scale: float, length: float, randomness: float)
snap bool or None
transform matplotlib.transforms.Transform
url str
visible bool
zorder float

Example 1:

import numpy as np

import matplotlib.cm as cm

import matplotlib.pyplot as plt

import matplotlib.cbook as cbook

from matplotlib.path import Path

from matplotlib.patches import PathPatch

delta = 0.025

x = y = np.arange(-3.0, 3.0, delta)

X, Y = np.meshgrid(x, y)

Z1 = np.exp(-X**2 - Y**2)

Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)

Z = (Z1 - Z2) * 2

path = Path([[0, 1], [1, 0], [0, -1], [-1, 0], [0, 1]])

patch = PathPatch(path, facecolor ='none')

fig, ax = plt.subplots()

ax.add_patch(patch)

im = ax.imshow(Z, interpolation ='bilinear', cmap = cm.gray,

origin ='lower', extent =[-3, 3, -3, 3],

clip_path = patch, clip_on = True)

im.set_clip_path(patch)

plt.show()

Output:
Matplotlib.patches.PathPatch in Python - GeeksforGeeks (1)

Example 2:

import matplotlib.pyplot as plt

import numpy as np

from matplotlib.path import Path

from matplotlib.patches import PathPatch

fig = plt.figure()

ax = fig.add_subplot(111, aspect ='equal')

path = Path([[0, 0], [0, 1], [1, 0], [0, 0]])

patch = PathPatch(path, facecolor ='none')

ax.add_patch(patch)

Z, Z2 = np.meshgrid(np.linspace(0, 1), np.linspace(0, 1))

im = plt.imshow(Z-Z2,

interpolation ='bilinear',

cmap = plt.cm.RdYlGn,

origin ='lower',

extent =[0, 1, 0, 1],

clip_path = patch,

clip_on = True)

im.set_clip_path(patch)

ax.set_xlim((0, 1))

ax.set_ylim((0, 1))

plt.show()

Output:
Matplotlib.patches.PathPatch in Python - GeeksforGeeks (2)



Next Article

matplotlib.pyplot.pcolormesh() in Python

R

RajuKumar19

Matplotlib.patches.PathPatch in Python - GeeksforGeeks (3)

Improve

Article Tags :

  • Python
  • Write From Home
  • Matplotlib patches-class
  • Python-Library

Practice Tags :

  • python

Similar Reads

  • Matplotlib.patches.PathPatch in Python Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. matplotlib.patches.PathPatch The matplotlib.patches.PathPatch class used to draw general 3 min read
  • matplotlib.pyplot.pcolormesh() 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. matplotlib.pyplot.pcolormesh() Function: The pcolormesh() function in pyplot module of matplotlib library 2 min read
  • matplotlib.patches.Rectangle in Python Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. matplotlib.patches.Rectangle The matplotlib.patches.Rectangle class is used to rectangle 2 min read
  • Matplotlib.patches.Arrow Class in Python Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. Matplotlib.patches.Arrow The matplotlib.patches.Arrow class is used to for patching an a 3 min read
  • Matplotlib.patches.Wedge class in Python Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. matplotlib.patches.Wedge The matplotlib.patches.Wedge class is used to add wedge-shaped 3 min read
  • Matplotlib.patches.Circle class in Python Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. matplotlib.patches.Circle The matplotlib.patches.Circle class is used to create a circul 3 min read
  • Matplotlib.patches.RegularPolygon class in Python Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. matplotlib.patches.RegularPolygon The matplotlib.patches.RegularPolygon class is used to 3 min read
  • Matplotlib.axes.Axes.add_patch() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. 2 min read
  • Matplotlib.patches.ArrowStyle class in Python Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. matplotlib.patches.ArrowStyle The matplotlib.patches.ArrowStyle class is a container cla 2 min read
  • Matplotlib.pyplot.copper() 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. matplotlib.pyplot.copper() Function The copper() function in pyplot module of matplotlib library is used 2 min read
Matplotlib.patches.PathPatch in Python - GeeksforGeeks (2025)

References

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Pres. Carey Rath

Last Updated:

Views: 5877

Rating: 4 / 5 (61 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Pres. Carey Rath

Birthday: 1997-03-06

Address: 14955 Ledner Trail, East Rodrickfort, NE 85127-8369

Phone: +18682428114917

Job: National Technology Representative

Hobby: Sand art, Drama, Web surfing, Cycling, Brazilian jiu-jitsu, Leather crafting, Creative writing

Introduction: My name is Pres. Carey Rath, I am a faithful, funny, vast, joyous, lively, brave, glamorous person who loves writing and wants to share my knowledge and understanding with you.