File: plotting.py

package info (click to toggle)
python-geopandas 1.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,752 kB
  • sloc: python: 26,021; makefile: 147; sh: 25
file content (73 lines) | stat: -rw-r--r-- 2,361 bytes parent folder | download | duplicates (2)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import random

from geopandas import GeoDataFrame, GeoSeries
from shapely.geometry import Point, LineString, Polygon, MultiPolygon
import numpy as np


class Bench:
    param_names = ["geom_type"]
    params = [("Point", "LineString", "Polygon", "MultiPolygon", "mixed")]

    def setup(self, geom_type):
        if geom_type == "Point":
            geoms = GeoSeries([Point(i, i) for i in range(1000)])
        elif geom_type == "LineString":
            geoms = GeoSeries(
                [
                    LineString([(random.random(), random.random()) for _ in range(5)])
                    for _ in range(100)
                ]
            )
        elif geom_type == "Polygon":
            geoms = GeoSeries(
                [
                    Polygon([(random.random(), random.random()) for _ in range(3)])
                    for _ in range(100)
                ]
            )
        elif geom_type == "MultiPolygon":
            geoms = GeoSeries(
                [
                    MultiPolygon(
                        [
                            Polygon(
                                [(random.random(), random.random()) for _ in range(3)]
                            )
                            for _ in range(3)
                        ]
                    )
                    for _ in range(20)
                ]
            )
        elif geom_type == "mixed":
            g1 = GeoSeries([Point(i, i) for i in range(100)])
            g2 = GeoSeries(
                [
                    LineString([(random.random(), random.random()) for _ in range(5)])
                    for _ in range(100)
                ]
            )
            g3 = GeoSeries(
                [
                    Polygon([(random.random(), random.random()) for _ in range(3)])
                    for _ in range(100)
                ]
            )

            geoms = g1
            geoms.iloc[np.random.randint(0, 100, 50)] = g2.iloc[:50]
            geoms.iloc[np.random.randint(0, 100, 33)] = g3.iloc[:33]

            print(geoms.geom_type.value_counts())

        df = GeoDataFrame({"geometry": geoms, "values": np.random.randn(len(geoms))})

        self.geoms = geoms
        self.df = df

    def time_plot_series(self, *args):
        self.geoms.plot()

    def time_plot_values(self, *args):
        self.df.plot(column="values")