-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Path.cleaned()
always returns a closed path
#28176
Comments
I don't think this creates a closed path. Looking at the path codes, it's Path(array([[0. , 0.5],
[4. , 0.5],
[4. , 0.5],
[0. , 0. ]]), array([1, 2, 2, 0], dtype=uint8)) |
Ah, I do see what you mean regarding the import matplotlib.pyplot as plt
import numpy as np
from matplotlib.path import Path
fig, axes = plt.subplots()
x = np.arange(0, 11, 1)
y = np.array([0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0])
path = Path(np.column_stack((x, y)))
print(f"{path.vertices=}")
axes.plot(
path.vertices[:, 0],
path.vertices[:, 1],
marker="o",
markersize=10,
label="Original",
)
path = path.cleaned(simplify=True)
print(f"{path.vertices=}")
axes.plot(
path.vertices[:, 0] + 15,
path.vertices[:, 1],
marker="o",
markersize=10,
label="Cleaned",
)
axes.legend()
plt.show() And the output is: I am trying to explicitly plot a simplified |
Ohhh I see, I'm not sure if it's recommended to plot |
Just reading a bit more about the So, to get the simplified vertices, one can write: vertices = np.array([p for p, _ in path.iter_segments(simplify=True)])
print(vertices) Output: [[ 0. 0.]
[ 5. 5.]
[10. 0.]
[10. 0.]] It's not quite as elegant as a single attribute access i.e. I'm still not sure why the simplified path duplicates the last coordinate though. Is that a bug? The actual implementation of the simplification algorithm is a bit dense for me at the moment. |
I'm inclined to say no, since it doesn't impact the behaviour of path drawing for Artists, and the vertices aren't meant to be used as data points. However, others might have a different opinion than mine? |
I do believe @AnsonTran is correct on all points. The relationship between #28179 was opened to discuss whether STOP in particular is needed, which would potentially resolve this particular use case, though |
I think dropping
or more dramatically https://matplotlib.org/stable/users/explain/artists/paths.html#compound-paths and the bezier examples. |
For sure, plotting vertices is not a correct visualization of the path in general. OTOH, I see the argument that |
Bug summary
I have a path - a simple line - which is created from a large number of points. I call the
cleaned(simplify=True)
method on it and it returns a closed pathCode for reproduction
Actual outcome
The path is simplified as I hoped, but it is now closed.
Expected outcome
For the path not to be closed.
Additional information
No response
Operating system
Ubuntu
Matplotlib Version
3.8.4
Matplotlib Backend
No response
Python version
3.12
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: