Bird
0
0

Given the code below, what will be the length of the simplified path vertices?

medium📝 Predict Output Q5 of 15
Matplotlib - Performance and Large Data
Given the code below, what will be the length of the simplified path vertices?
import matplotlib.path as mpath
import matplotlib.pyplot as plt

verts = [(0, 0), (0.1, 0.1), (0.2, 0.2), (5, 5)]
p = mpath.Path(verts)
p._simplify_threshold = 1.0
simplified = p.cleaned()
print(len(simplified.vertices))
A2
B4
C3
D1
Step-by-Step Solution
Solution:
  1. Step 1: Understand the original vertices

    Original vertices are 4 points: (0,0), (0.1,0.1), (0.2,0.2), (5,5), all colinear on the line y=x.
  2. Step 2: Effect of _simplify_threshold and cleaned()

    With threshold 1.0, cleaned() removes intermediate vertices where perpendicular distance to neighboring segment is < threshold. Since distances are 0, it reduces to endpoints.
  3. Step 3: Count simplified vertices

    After simplification, 2 vertices remain: (0,0) and (5,5).
  4. Final Answer:

    2 -> Option A
  5. Quick Check:

    cleaned() on colinear points = 2 [OK]
Quick Trick: cleaned() returns simplified path based on threshold [OK]
Common Mistakes:
  • Assuming cleaned() returns original vertices
  • Ignoring threshold effect on colinear points
  • Expecting all points to be removed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes