Skip to content
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

ENH: spatial: faster 2D Voronoi and Convex Hull plotting #5061

Merged
merged 3 commits into from Oct 10, 2015

Conversation

grlee77
Copy link
Contributor

@grlee77 grlee77 commented Jul 16, 2015

This pull request modifies voronoi_plot_2d and convex_hull_plot_2d to use matplotlib.collections.LineCollection objects. This removes the need for repeatedly calling ax.plot on each individual line segment and speeds up plotting. This improvement is especially dramatic for the Voronoi case (approximately 13 times faster for me in the example below!).

On my PC, for a set of 2000 randomly generated 2D points I got the following speedups
voronoi_plot_2d : previously 8.45 s -> now 0.63 s
convex_hull_plot_2d:| previously 111 ms -> now 83 ms

I also added an optional kwarg to voronoi_plot_2d that can be used to avoid adding the vertices to the plot. To my eye this looks cleaner, especially when there are a large number of points, but I have left the old behavior as the default.

@grlee77 grlee77 changed the title ENH: spatial: faster 2D Voronoi and Covex Hull plotting ENH: spatial: faster 2D Voronoi and Convex Hull plotting Jul 16, 2015
_adjust_bounds(ax, hull.points)

return ax.figure


@_held_figure
def voronoi_plot_2d(vor, ax=None):
def voronoi_plot_2d(vor, ax=None, **kw):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just add show_vertices=True here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it as you suggest initially, but the _held_figure decorator was raising the following error:

TypeError: _held_figure() takes from 2 to 3 positional arguments but 4 were given

pv added a commit that referenced this pull request Oct 10, 2015
ENH: spatial: faster 2D Voronoi and Convex Hull plotting
@pv pv merged commit 99e8bdf into scipy:master Oct 10, 2015
@pv
Copy link
Member

pv commented Oct 10, 2015

Thanks, merged

@pv pv added this to the 0.17.0 milestone Oct 10, 2015
@rgommers rgommers added scipy.spatial enhancement A new feature or improvement labels Oct 10, 2015
@grlee77 grlee77 deleted the fast_voronoi_plotting branch August 19, 2020 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or improvement scipy.spatial
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants