Example #1
0
def plot_lines(ax, ob):
    color = color_issimple(ob)
    for line in ob:
        plot_line(ax, line, color=color, alpha=0.7, zorder=2)
Example #2
0
from descartes.patch import PolygonPatch

from figures import GRAY, BLUE, SIZE, set_limits, plot_line

fig = pyplot.figure(1, figsize=SIZE, dpi=90)
fig.set_frameon(True)

# 1
ax = fig.add_subplot(121)

points2 = MultiPoint([(0, 0), (2, 2)])
for p in points2:
    ax.plot(p.x, p.y, 'o', color=GRAY)
hull2 = points2.convex_hull
plot_line(ax, hull2, color=BLUE, alpha=0.5, zorder=2)

ax.set_title('a) N = 2')

set_limits(ax, -1, 4, -1, 3)

#2
ax = fig.add_subplot(122)

points1 = MultiPoint([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)])

for p in points1:
    ax.plot(p.x, p.y, 'o', color=GRAY)
hull1 = points1.convex_hull
patch1 = PolygonPatch(hull1, facecolor=BLUE, edgecolor=BLUE, alpha=0.5, zorder=2)
ax.add_patch(patch1)
Example #3
0
from matplotlib.font_manager import FontProperties

font_song = FontProperties(fname="/usr/share/fonts/xpfonts/simfang.ttf")

# from pygiser import BLUE, GRAY, set_limits, plot_line
from figures import SIZE, BLUE, GRAY, plot_line, set_limits, BLACK, DARKGRAY

line = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)])

fig = pyplot.figure(1, figsize=SIZE, dpi=90)

# 1
ax = fig.add_subplot(121)

plot_line(ax, line)

dilated = line.buffer(0.5, cap_style=3)
patch1 = PolygonPatch(dilated, fc=GRAY, ec=GRAY, alpha=0.5, zorder=2)
ax.add_patch(patch1)

ax.set_title('a) 膨胀', fontproperties=font_song)  # , cap_style=3

set_limits(ax, -1, 4, -1, 3)

# 2
ax = fig.add_subplot(122)

patch2a = PolygonPatch(dilated, fc=GRAY, ec=GRAY, alpha=0.5, zorder=1)
ax.add_patch(patch2a)
invalid_poly = Polygon([(0, 2), (0, 1), (2, 0), (0, 0), (0, 2)])
valid_poly = make_valid(invalid_poly)

fig = pyplot.figure(1, figsize=SIZE, dpi=90)
fig.set_frameon(True)

invalid_ax = fig.add_subplot(121)

patch = PolygonPatch(invalid_poly,
                     facecolor=BLUE,
                     edgecolor=BLUE,
                     alpha=0.5,
                     zorder=2)
invalid_ax.add_patch(patch)

set_limits(invalid_ax, -1, 3, -1, 3)

valid_ax = fig.add_subplot(122)

patch = PolygonPatch(valid_poly[0],
                     facecolor=BLUE,
                     edgecolor=BLUE,
                     alpha=0.5,
                     zorder=2)
valid_ax.add_patch(patch)

plot_line(valid_ax, valid_poly[1], color=RED, linewidth=1)

set_limits(valid_ax, -1, 3, -1, 3)

pyplot.show()
Example #5
0
from matplotlib import pyplot
from shapely.geometry import LineString
from shapely import affinity

from figures import SIZE, BLUE, GRAY, set_limits, plot_line, add_origin

fig = pyplot.figure(1, figsize=SIZE, dpi=90)

line = LineString([(1, 3), (1, 1), (4, 1)])

# 1
ax = fig.add_subplot(121)

plot_line(ax, line, GRAY)
plot_line(ax, affinity.rotate(line, 90, 'center'), BLUE)
add_origin(ax, line, 'center')

ax.set_title(u"90\N{DEGREE SIGN}, default origin (center)")

set_limits(ax, 0, 5, 0, 4)

# 2
ax = fig.add_subplot(122)

plot_line(ax, line, GRAY)
plot_line(ax, affinity.rotate(line, 90, 'centroid'), BLUE)
add_origin(ax, line, 'centroid')

ax.set_title(u"90\N{DEGREE SIGN}, origin='centroid'")

set_limits(ax, 0, 5, 0, 4)
Example #6
0
from matplotlib import pyplot
from shapely.geometry import LineString
from descartes import PolygonPatch

from figures import SIZE, BLUE, GRAY, set_limits, plot_line

line = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)])

fig = pyplot.figure(1, figsize=SIZE, dpi=90)

# 1
ax = fig.add_subplot(121)

plot_line(ax, line)

dilated = line.buffer(0.5, cap_style=3)
patch1 = PolygonPatch(dilated, fc=BLUE, ec=BLUE, alpha=0.5, zorder=2)
ax.add_patch(patch1)

ax.set_title('a) dilation, cap_style=3')

set_limits(ax, -1, 4, -1, 3)

#2
ax = fig.add_subplot(122)

patch2a = PolygonPatch(dilated, fc=GRAY, ec=GRAY, alpha=0.5, zorder=1)
ax.add_patch(patch2a)

eroded = dilated.buffer(-0.3)
Example #7
0
from descartes.patch import PolygonPatch

from figures import GRAY, BLUE, SIZE, set_limits, plot_line

fig = pyplot.figure(1, figsize=SIZE, dpi=90)
fig.set_frameon(True)

# 1
ax = fig.add_subplot(121)

points2 = MultiPoint([(0, 0), (2, 2)])
for p in points2:
    ax.plot(p.x, p.y, 'o', color=GRAY)
hull2 = points2.convex_hull
plot_line(ax, hull2, color=BLUE, alpha=0.5, zorder=2)

ax.set_title('a) N = 2')

set_limits(ax, -1, 4, -1, 3)

#2
ax = fig.add_subplot(122)

points1 = MultiPoint([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)])

for p in points1:
    ax.plot(p.x, p.y, 'o', color=GRAY)
hull1 = points1.convex_hull
patch1 = PolygonPatch(hull1,
                      facecolor=BLUE,
Example #8
0
from matplotlib.font_manager import FontProperties
font_song = FontProperties(fname="/usr/share/fonts/xpfonts/simfang.ttf")
# from pygiser import GRAY, BLUE, set_limits, plot_line
from figures import SIZE, BLUE, GRAY, plot_line, set_limits, DARKGRAY

fig = pyplot.figure(1, figsize=SIZE, dpi=90)
fig.set_frameon(True)

# 1
ax = fig.add_subplot(121)

points2 = MultiPoint([(0, 1), (2, 1), (3, 1)])
for p in points2:
    ax.plot(p.x, p.y, 'o', color=DARKGRAY)
hull2 = points2.convex_hull
plot_line(ax, hull2, color=GRAY, alpha=0.5, zorder=2)

ax.set_title('a) 点分布在水平线上', fontproperties=font_song)

set_limits(ax, -1, 4, -1, 3)

# 2
ax = fig.add_subplot(122)

points1 = MultiPoint([(1, 0), (3, 0.6), (1.5, 2), (0, 1.4)])

for p in points1:
    ax.plot(p.x, p.y, 'o', color=DARKGRAY)
hull1 = points1.envelope

patch1 = PolygonPatch(hull1,
Example #9
0
def plot_lines(ax, ob):
    color = color_issimple(ob)
    for line in ob:
        plot_line(ax, line, color=color, alpha=0.7, zorder=2)