コード例 #1
0
 def plot_guppy_bins(self, bins=True):
     self.ax.cla()  # clear axes
     # plot tank
     ext = [(0, 0), (0, 100), (100, 100), (100, 0)]
     polygon = shapely.geometry.Polygon(ext)
     plot_coords(self.ax, polygon.exterior)
     patch = PolygonPatch(polygon, facecolor=BLUE, edgecolor=BLACK, alpha=0.6, zorder=1)
     self.ax.add_patch(patch)
     # plot bins
     if bins:
         for i, p in enumerate(self.bins):
             patch = PolygonPatch(p, facecolor=BLACK, edgecolor=YELLOW,
                                  alpha=(1 - self.agent_view[i]), zorder=1)
             self.ax.add_patch(patch)
     # plot fishes
     ellipse = patches.Ellipse((self.obs_pos[0], self.obs_pos[1]), 2, 7, rad_to_deg360(self.obs_angle - pi / 2))
     self.ax.add_patch(ellipse)
     for i in range(len(self.others)):
         position = (self.others[i][0], self.others[i][1])
         ellipse = patches.Ellipse(position, 2, 7, rad_to_deg360(self.others_angle[i] - pi / 2))
         self.ax.add_patch(ellipse)
     # plot legend
     self.ax.text(110, 100, 'angle: {:.2f}°'.format(degrees(self.obs_angle)))
     self.ax.text(110, 90, 'o_vector: ({:.2f},{:.2f})'.format(self.obs_ori[0], self.obs_ori[1]))
     self.ax.text(110, 80, 'angular turn: {:.10f}'.format(self.loc_vec[0]))
     self.ax.text(110, 70, 'linear speed: {:.10f}'.format(self.loc_vec[1]))
     # self.ax.text(110, 60, 'dist travelled: {:.10f}'.format(self.dist_difference))
     pyplot.show(block=False)
     pyplot.pause(0.00000000000001)
コード例 #2
0
def plotthebitch(lines: list):
    """
    ha ha chart go brrrr 
    """
    i = 121
    for item in lines:
        ax = fig.add_subplot(i)
        plot_coords(ax, item)
        plot_bounds(ax, item)
        plot_line_issimple(ax, item, alpha=0.7)
        i += 1
    pyplot.show()
コード例 #3
0
 def display_matplotlib(self):
     fig = plt.figure(1, figsize=SIZE, dpi=90)
     ax = fig.add_subplot(111)
     for polygon in self.scene:
         plot_coords(ax, polygon.exterior)
         patch = patches.Polygon(polygon.exterior.xy,
                                 facecolor=color_isvalid(self.scene),
                                 edgecolor=color_isvalid(self.scene,
                                                         valid=BLUE),
                                 alpha=0.5,
                                 zorder=2)
         ax.add_patch(patch)
     plt.show()
コード例 #4
0
def plotTest(sheet, agents, fname):
    fig = plt.figure(figsize=SIZE, dpi=90)

    # 3: invalid polygon, ring touch along a line
    ax = fig.add_subplot(121)
    plot_coords(ax, sheet.exterior)

    for _a in agents:
        patch = PolygonPatch(_a,
                             facecolor=color_isvalid(_a),
                             edgecolor=color_isvalid(_a, valid=BLUE),
                             alpha=0.5,
                             zorder=2)
        ax.add_patch(patch)

    plt.savefig(fname)
コード例 #5
0
    def plot_wall_rays(self):
        self.ax.cla()
        # plot tank
        ext = [(0, 0), (0, 100), (100, 100), (100, 0)]
        polygon = shapely.geometry.Polygon(ext)
        plot_coords(self.ax, polygon.exterior)
        patch = PolygonPatch(polygon, facecolor=BLUE, edgecolor=BLACK, alpha=0.6, zorder=1)
        self.ax.add_patch(patch)
        # plot rays
        self.ax.plot(self.obs_pos[0], self.obs_pos[1], "ro")
        # uncomment line for intersections in wall_distances
        for (x, y) in self.intersections:
            self.ax.plot([self.obs_pos[0], x], [self.obs_pos[1], y])

        pyplot.show(block=False)
        pyplot.pause(0.00000000001)
コード例 #6
0
fig = pyplot.figure(1, figsize=SIZE, dpi=90)  # 1, figsize=(10, 4), dpi=180)

lines = [((0, 0), (2, 2)), ((0, 0), (0, 2)), ((0, 2), (2, 2)),
         ((2, 2), (2, 0)), ((2, 0), (0, 0))]
the_line = linemerge(lines)
the_poly = polygonize(lines)

# a = LineString([(0, 0), (1, 1), (1, 2), (2, 2)])
# b = LineString([(0, 0), (1, 1), (2, 1), (2, 2)])

# 1: disconnected multilinestring
ax = fig.add_subplot(131)

for x in lines:
    plot_coords(ax, LineString(x))
# plot_coords(ax, b)

# x, y = the_line.xy

xx = [t[0][0] for t in lines]
yy = [t[0][1] for t in lines]

ax.scatter(xx, yy)
# for uu in lines:
#     ax.plot(uu[0][0], uu[0][1],  color=GRAY, alpha=0.5, linewidth=3, solid_capstyle='round', zorder=2)

# x, y = b.xy
# ax.plot(x, y, color=GREEN, alpha=0.5, linewidth=3, solid_capstyle='round', zorder=2)

for x in lines:
コード例 #7
0
    ax.plot(x,
            y,
            color=v_color(ob),
            alpha=0.7,
            linewidth=3,
            solid_capstyle='round',
            zorder=2)


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

# 1: simple line
ax = fig.add_subplot(121)
line = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)])

plot_coords(ax, line)
plot_bounds(ax, line)
plot_line_issimple(ax, line, alpha=0.7)

ax.set_title('a) simple')

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

#2: complex line
ax = fig.add_subplot(122)
line2 = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (-1, 1), (1, 0)])

plot_coords(ax, line2)
plot_bounds(ax, line2)
plot_line_issimple(ax, line2, alpha=0.7)
コード例 #8
0
from matplotlib.font_manager import FontProperties
font_song = FontProperties(fname="/usr/share/fonts/xpfonts/simfang.ttf")

from figures import BLUE, SIZE, set_limits, plot_coords, color_isvalid

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

# 3: invalid polygon, ring touch along a line
ax = fig.add_subplot(121)

ext = [(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)]
int = [(0.5, 0), (1.5, 0), (1.5, 1), (0.5, 1), (0.5, 0)]
polygon = Polygon(ext, [int])

plot_coords(ax, polygon.interiors[0])
plot_coords(ax, polygon.exterior)

patch = PolygonPatch(polygon,
                     facecolor=color_isvalid(polygon),
                     edgecolor=color_isvalid(polygon, valid=BLUE),
                     alpha=0.5,
                     zorder=2)
ax.add_patch(patch)

ax.set_title('c) 无效', fontproperties=font_song)

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

# 4: invalid self-touching ring
ax = fig.add_subplot(122)
コード例 #9
0
ファイル: linestring.py プロジェクト: Toblerity/Shapely
    x, y = zip(*list((p.x, p.y) for p in ob.boundary))
    ax.plot(x, y, "o", color="#000000", zorder=1)


def plot_line(ax, ob):
    x, y = ob.xy
    ax.plot(x, y, color=v_color(ob), alpha=0.7, linewidth=3, solid_capstyle="round", zorder=2)


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

# 1: simple line
ax = fig.add_subplot(121)
line = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)])

plot_coords(ax, line)
plot_bounds(ax, line)
plot_line_issimple(ax, line, alpha=0.7)

ax.set_title("a) simple")

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

# 2: complex line
ax = fig.add_subplot(122)
line2 = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (-1, 1), (1, 0)])

plot_coords(ax, line2)
plot_bounds(ax, line2)
plot_line_issimple(ax, line2, alpha=0.7)
コード例 #10
0
from matplotlib import pyplot
from shapely.geometry import LineString
from figures import BLUE, GRAY, YELLOW, GREEN, SIZE, set_limits, plot_coords

fig = pyplot.figure(1, figsize=SIZE, dpi=90) #1, figsize=(10, 4), dpi=180)

a = LineString([(0, 0), (1, 1), (1,2), (2,2)])
b = LineString([(0, 0), (1, 1), (2,1), (2,2)])

# 1: disconnected multilinestring
ax = fig.add_subplot(121)

plot_coords(ax, a)
plot_coords(ax, b)

x, y = a.xy
ax.plot(x, y, color=YELLOW, alpha=0.5, linewidth=3, solid_capstyle='round', zorder=2)

x, y = b.xy
ax.plot(x, y, color=GREEN, alpha=0.5, linewidth=3, solid_capstyle='round', zorder=2)

ax.set_title('a) lines')

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

#2: invalid self-touching ring
ax = fig.add_subplot(122)

x, y = a.xy
ax.plot(x, y, color=GRAY, alpha=0.7, linewidth=1, solid_capstyle='round', zorder=1)
x, y = b.xy
コード例 #11
0
from matplotlib import pyplot
from shapely.geometry import LineString
from figures import BLUE, GRAY, YELLOW, GREEN, SIZE, set_limits, plot_coords

fig = pyplot.figure(1, figsize=SIZE, dpi=90)  #1, figsize=(10, 4), dpi=180)

a = LineString([(0, 0), (1, 1), (1, 2), (2, 2)])
b = LineString([(0, 0), (1, 1), (2, 1), (2, 2)])

# 1: disconnected multilinestring
ax = fig.add_subplot(121)

plot_coords(ax, a)
plot_coords(ax, b)

x, y = a.xy
ax.plot(x,
        y,
        color=YELLOW,
        alpha=0.5,
        linewidth=3,
        solid_capstyle='round',
        zorder=2)

x, y = b.xy
ax.plot(x,
        y,
        color=GREEN,
        alpha=0.5,
        linewidth=3,
        solid_capstyle='round',
コード例 #12
0
ファイル: polygon2.py プロジェクト: Toblerity/Shapely
from matplotlib.patches import Circle
from shapely.geometry import Polygon
from descartes.patch import PolygonPatch

from figures import BLUE, SIZE, set_limits, plot_coords, color_isvalid
    
fig = pyplot.figure(1, figsize=SIZE, dpi=90)

# 3: invalid polygon, ring touch along a line
ax = fig.add_subplot(121)

ext = [(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)]
int = [(0.5, 0), (1.5, 0), (1.5, 1), (0.5, 1), (0.5, 0)]
polygon = Polygon(ext, [int])

plot_coords(ax, polygon.interiors[0])
plot_coords(ax, polygon.exterior)

patch = PolygonPatch(polygon, facecolor=color_isvalid(polygon), edgecolor=color_isvalid(polygon, valid=BLUE), alpha=0.5, zorder=2)
ax.add_patch(patch)

ax.set_title('c) invalid')

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

#4: invalid self-touching ring
ax = fig.add_subplot(122)
ext = [(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)]
int_1 = [(0.5, 0.25), (1.5, 0.25), (1.5, 1.25), (0.5, 1.25), (0.5, 0.25)]
int_2 = [(0.5, 1.25), (1, 1.25), (1, 1.75), (0.5, 1.75)]
# int_2 = [
コード例 #13
0
ファイル: multipolygon.py プロジェクト: Toblerity/Shapely
from descartes.patch import PolygonPatch

from figures import BLUE, SIZE, set_limits, plot_coords, color_isvalid
    
fig = pyplot.figure(1, figsize=SIZE, dpi=90)

# 1: valid multi-polygon
ax = fig.add_subplot(121)

a = [(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)]
b = [(1, 1), (1, 2), (2, 2), (2, 1), (1, 1)]

multi1 = MultiPolygon([[a, []], [b, []]])

for polygon in multi1:
    plot_coords(ax, polygon.exterior)
    patch = PolygonPatch(polygon, facecolor=color_isvalid(multi1), edgecolor=color_isvalid(multi1, valid=BLUE), alpha=0.5, zorder=2)
    ax.add_patch(patch)

ax.set_title('a) valid')

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

#2: invalid self-touching ring
ax = fig.add_subplot(122)

c = [(0, 0), (0, 1.5), (1, 1.5), (1, 0), (0, 0)]
d = [(1, 0.5), (1, 2), (2, 2), (2, 0.5), (1, 0.5)]

multi2 = MultiPolygon([[c, []], [d, []]])
コード例 #14
0
from matplotlib import pyplot
from shapely.geometry.polygon import LinearRing

from figures import SIZE, set_limits, plot_coords, plot_line_isvalid

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

# 1: valid ring
ax = fig.add_subplot(121)
ring = LinearRing([(0, 0), (0, 2), (1, 1), (2, 2), (2, 0), (1, 0.8), (0, 0)])

plot_coords(ax, ring)
plot_line_isvalid(ax, ring, alpha=0.7)

ax.set_title('a) valid')

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

#2: invalid self-touching ring
ax = fig.add_subplot(122)
ring2 = LinearRing([(0, 0), (0, 2), (1, 1), (2, 2), (2, 0), (1, 1), (0, 0)])

plot_coords(ax, ring2)
plot_line_isvalid(ax, ring2, alpha=0.7)

ax.set_title('b) invalid')

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

pyplot.show()
コード例 #15
0
font_song = FontProperties(fname="/usr/share/fonts/xpfonts/simfang.ttf")

from figures import BLUE, SIZE, set_limits, plot_coords, color_isvalid

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

# 1: valid multi-polygon
ax = fig.add_subplot(121)

a = [(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)]
b = [(1, 1), (1, 2), (2, 2), (2, 1), (1, 1)]

multi1 = MultiPolygon([[a, []], [b, []]])

for polygon in multi1:
    plot_coords(ax, polygon.exterior)
    patch = PolygonPatch(polygon,
                         facecolor=color_isvalid(multi1),
                         edgecolor=color_isvalid(multi1, valid=BLUE),
                         alpha=0.5,
                         zorder=2)
    ax.add_patch(patch)

ax.set_title('a) 有效', fontproperties=font_song)

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

# 2: invalid self-touching ring
ax = fig.add_subplot(122)

c = [(0, 0), (0, 1.5), (1, 1.5), (1, 0), (0, 0)]