%matplotlib inline
import matplotlib.pyplot as plt
x = [1,2,3,4]
y = [1,2,3,4]
m = [[15,14,13,12],[14,12,10,8],[13,10,7,4],[12,8,4,0]]
cs = plt.contour(x,y,m)
cm = plt.contourf(x,y,m)
from shapely.geometry import LineString
def plot_line(ax, ob):
x, y = ob.xy
ax.plot(x, y, color='b')
lines = []
for i in range(len(cs.collections)):
p = cs.collections[i].get_paths()[0]
v = p.vertices
x = v[:,0]
y = v[:,1]
lines.append(LineString([(i[0], i[1]) for i in zip(x,y)]))
import matplotlib.pyplot as plt
def plot_line(ax, ob):
x, y = ob.xy
ax.plot(x, y, color='b')
fig = plt.figure()
ax = fig.gca()
for line in lines:
plot_line(ax, line)
from shapely.geometry import Polygon
polys = []
for i in range(len(cm.collections)):
p = cm.collections[i].get_paths()[0]
v = p.vertices
x = v[:,0]
y = v[:,1]
polys.append(Polygon([(i[0], i[1]) for i in zip(x,y)]))
import matplotlib.pyplot as plt
from descartes import PolygonPatch
BLUE = '#6699cc'
fig = plt.figure()
ax = fig.gca()
for i in polys:
ax.add_patch(PolygonPatch(i, fc=BLUE, ec=BLUE, alpha=0.5, zorder=2 ))
ax.axis('scaled')
(1.0, 4.0, 1.0, 4.0)
BLUE = '#6699cc'
fig = plt.figure()
ax = fig.gca()
ax.add_patch(PolygonPatch(polys[5], fc=BLUE, ec=BLUE, alpha=0.5, zorder=2 ))
ax.axis('scaled')
(1.0, 4.0, 1.0, 4.0)
polys[5]