Plotting disabled objects with nice desktop and matplotlib

I need to build a list of disabled circles that I created for other style purposes.

I tried to do as shown in the example http://toblerity.org/shapely/manual.html#cascading-unions (see code ), but this only works if the circles overlap and the overall thing is related (which not in my case). As you can see, replacing the line

polygons = [Point(i, 0).buffer(0.7) for i in range(5)]

      

from

polygons = [Point(i, 0).buffer(0.7) for i in (0,4)]

      

which breaks down also AssertionError

for the thing not being a cartesian polygon (or using matplotlib failing assert vertices.ndim == 2

in case someone notices the descartes statement as a test)

Looking at the docs for matplotlib.path.Path , it seems like it is possible to use MOVETO to achieve this, but it doesn't seem to support it. It's right? What workarounds do I have?

+3


source to share


1 answer


The following code works:

from shapely.ops import cascaded_union
from shapely.geometry import Point
import random
from matplotlib.patches import Polygon
import pylab as pl
import numpy as np

circles = [Point(random.random(), random.random()).buffer(random.random() * 0.1) 
            for i in range(100)]

polygons = cascaded_union(circles)

fig, ax = pl.subplots(figsize=(8, 8))

for polygon in polygons:
    mpl_poly = Polygon(np.array(polygon.exterior), facecolor="g", lw=0, alpha=0.4)
    ax.add_patch(mpl_poly)

ax.relim()
ax.autoscale()

      



output:

enter image description here

+4


source







All Articles