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.Pathobject.
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.025x = 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:

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:

Recommended Posts:
- Important differences between Python 2.x and Python 3.x with examples
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Sort Python Dictionaries by Key or Value
- Python | Merge Python key values to list
- Reading Python File-Like Objects from C | Python
- Python | Add Logging to a Python Script
- Python | Add Logging to Python Libraries
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- Python | Visualizing O(n) using Python
- Python | Index of Non-Zero elements in Python list
- Python | Convert list to Python array
- MySQL-Connector-Python module in Python
- Python - Read blob object in python using wand library
- Python | PRAW - Python Reddit API Wrapper
- twitter-text-python (ttp) module - Python
- Reusable piece of python functionality for wrapping arbitrary blocks of code : Python Context Managers
- Python program to check if the list contains three consecutive common numbers in Python
- Creating and updating PowerPoint Presentations in Python using python - pptx
- How to write an empty function in Python - pass statement?
- Operator Functions in Python | Set 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

