0
0
Matplotlibdata~10 mins

Path simplification in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the path simplification function from matplotlib.

Matplotlib
from matplotlib.path import [1]
Drag options to blanks, or click blank then click option'
Asimplify_path
BPathPatch
CPath
DPathEffect
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to import a function named 'simplify_path' which does not exist.
Importing 'PathPatch' which is for patches, not paths.
2fill in blank
medium

Complete the code to create a Path object from a list of points.

Matplotlib
import numpy as np
points = np.array([[0, 0], [1, 2], [2, 3], [3, 1]])
codes = [[1], 2, 2, 2]
path = Path(points, codes)
Drag options to blanks, or click blank then click option'
APath.MOVETO
B0
CPath.LINETO
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using integer 1 instead of the constant Path.MOVETO.
Using Path.LINETO for the first point which is incorrect.
3fill in blank
hard

Fix the error in the code to simplify the path using the 'simplify_threshold' parameter.

Matplotlib
simplified_path = path.cleaned([1]=0.1)
Drag options to blanks, or click blank then click option'
Asimplify
Bsimplify_threshold
Cthreshold
Dclean_threshold
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'simplify' instead of 'simplify_threshold'.
Using 'threshold' or 'clean_threshold' which are invalid parameter names.
4fill in blank
hard

Fill both blanks to create a simplified path and plot it with matplotlib.

Matplotlib
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
simplified = path.cleaned([1]=0.05)
ax.plot(*simplified.vertices.T, [2]='blue')
plt.show()
Drag options to blanks, or click blank then click option'
Asimplify_threshold
Bcolor
Clinewidth
Dlinestyle
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'linewidth' or 'linestyle' instead of 'color' for line color.
Using wrong parameter name for simplification.
5fill in blank
hard

Fill all three blanks to create a path, simplify it, and plot both original and simplified paths with different colors.

Matplotlib
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
codes = [Path.MOVETO, Path.LINETO, Path.LINETO, Path.LINETO]
points = [[0, 0], [1, 2], [2, 3], [3, 1]]
path = Path([1], [2])
simplified = path.cleaned([3]=0.1)
ax.plot(*path.vertices.T, color='red', label='Original')
ax.plot(*simplified.vertices.T, color='green', label='Simplified')
ax.legend()
plt.show()
Drag options to blanks, or click blank then click option'
Apoints
Bcodes
Csimplify_threshold
Dvertices
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping points and codes in Path constructor.
Using 'vertices' instead of 'points' or 'codes'.
Using wrong parameter name for simplification.