File: scale.py

package info (click to toggle)
python-shapely 2.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 2,564 kB
  • sloc: python: 18,650; ansic: 6,615; makefile: 88; sh: 62
file content (38 lines) | stat: -rw-r--r-- 985 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import matplotlib.pyplot as plt
from shapely.geometry import Polygon
from shapely import affinity
from shapely.plotting import plot_polygon

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

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

triangle = Polygon([(1, 1), (2, 3), (3, 1)])

# 1
ax = fig.add_subplot(121)

plot_polygon(triangle, ax=ax, add_points=False, color=GRAY, alpha=0.5)
triangle_a = affinity.scale(triangle, xfact=1.5, yfact=-1)
plot_polygon(triangle_a, ax=ax, add_points=False, color=BLUE, alpha=0.5)

add_origin(ax, triangle, 'center')

ax.set_title("a) xfact=1.5, yfact=-1")

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

# 2
ax = fig.add_subplot(122)

plot_polygon(triangle, ax=ax, add_points=False, color=GRAY, alpha=0.5)
triangle_b = affinity.scale(triangle, xfact=2, origin=(1, 1))
plot_polygon(triangle_b, ax=ax, add_points=False, color=BLUE, alpha=0.5)

add_origin(ax, triangle, (1, 1))

ax.set_title("b) xfact=2, origin=(1, 1)")

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

plt.show()