geoplotpy 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ Metadata-Version: 2.4
2
+ Name: geoplotpy
3
+ Version: 0.1.0
@@ -0,0 +1,32 @@
1
+ """
2
+ geoplotpy is a library for plotting geography maps.
3
+
4
+ Example:
5
+ >>> import geoplotpy as gpp
6
+ >>> fig, ax = gpp.plot_map()
7
+ >>> gpp.save_fig('map.png')
8
+
9
+ Version:
10
+ 0.1.0
11
+ """
12
+
13
+ __version__ = '0.1.0'
14
+
15
+ from .plot import (
16
+ plot_maps,
17
+ plot_map,
18
+ plot_provinces,
19
+ get_colorbar,
20
+ plot_colorbar,
21
+ save_fig
22
+ )
23
+
24
+ __all__ = [
25
+ 'plot_maps',
26
+ 'plot_map',
27
+ 'plot_provinces',
28
+ 'get_colorbar',
29
+ 'plot_colorbar',
30
+ 'save_fig',
31
+ '__version__'
32
+ ]
@@ -0,0 +1,10 @@
1
+ bounds = {
2
+ 'O3': [0, 50, 100, 130, 160, 800]
3
+ }
4
+ colors = {
5
+ 'AQI': ['#00E400', '#FFFF00', '#FF7E00', '#FF0000', '#99004C'],
6
+ 'AQI6': ['#6ED34A', '#D8E94A', '#FFF066', '#FF9A4A', '#FF5A73', '#A64DB6'],
7
+ 'RB': ['#000088', '#0022CD', '#185FFB', '#3A97F8', '#5ECFFA', '#82EEFB', '#A3F9F7', '#C4F9F3', '#E3FAF6', '#FFFFFF', '#FFFFFF', '#FAFBE5', '#F5F69B', '#F7D45D', '#FAA72B', '#FB7524', '#FB4625', '#F51317', '#D5000A', '#9E0000'],
8
+ 'Q4': ['#3B82F6', '#22C55E', '#F59E0B', '#EF4444'],
9
+ 'turbo8': ['#FFFFFF', '#4776EE', '#1BD0D5', '#61FCDC', '#D2E935', '#FE9B2D', '#DA3907', '#7A0403']
10
+ }
@@ -0,0 +1,175 @@
1
+ import numpy as np
2
+ import matplotlib.pyplot as plt
3
+ import matplotlib.ticker as mticker
4
+ import matplotlib.colors as mcolors
5
+ import matplotlib.figure as mfigure
6
+ import matplotlib.axes as maxes
7
+ import matplotlib.collections as mcollections
8
+ import matplotlib.transforms as mtransforms
9
+ import cartopy.crs as ccrs
10
+ import cartopy.feature as cfeature
11
+ import geopandas as gpd
12
+ from . import colorbar as clb
13
+
14
+ def plot_maps(
15
+ nrows: int = 1,
16
+ ncols: int = 1,
17
+ figsize: tuple[float, float] = (8, 8),
18
+ west: float = 100,
19
+ east: float = 137,
20
+ south: float = 16,
21
+ north: float = 54,
22
+ gridlines: bool = True,
23
+ gridstep: float = 10,
24
+ ) -> tuple[mfigure.Figure, np.ndarray]:
25
+ """
26
+ Plot subplots.
27
+ Args:
28
+ nrows: The number of rows of the subplots.
29
+ ncols: The number of columns of the subplots.
30
+ figsize: The size of the maps.
31
+ west: The west bound of the maps.
32
+ east: The east bound of the maps.
33
+ south: The south bound of the maps.
34
+ north: The north bound of the maps.
35
+ gridlines: Whether to plot gridlines.
36
+ gridstep: The step of the gridlines.
37
+ Returns:
38
+ A tuple of the figure and the axes.
39
+ """
40
+ fig, axes = plt.subplots(
41
+ nrows = nrows,
42
+ ncols = ncols,
43
+ figsize = (figsize[0] * ncols, figsize[1] * nrows),
44
+ squeeze = False,
45
+ subplot_kw = {'projection': ccrs.PlateCarree(central_longitude = (west + east) / 2)}
46
+ )
47
+
48
+ for i in range(nrows):
49
+ for j in range(ncols):
50
+ ax = axes[i, j]
51
+ ax.set_extent([west, east, south, north], crs = ccrs.PlateCarree())
52
+ ax.add_feature(cfeature.COASTLINE, linewidth = 0.8)
53
+ ax.add_feature(cfeature.BORDERS, linestyle = ':', linewidth = 0.8)
54
+ if gridlines:
55
+ gl = ax.gridlines(crs = ccrs.PlateCarree(), draw_labels = True, linewidth = 1, color = 'gray', alpha = 0.5, linestyle = '--')
56
+ gl.top_labels = False
57
+ gl.right_labels = False
58
+ gl.xlocator = mticker.FixedLocator(np.arange(np.ceil(west / gridstep) * gridstep, np.floor(east / gridstep) * gridstep + gridstep, gridstep))
59
+ gl.ylocator = mticker.FixedLocator(np.arange(np.ceil(south / gridstep) * gridstep, np.floor(north / gridstep) * gridstep + gridstep, gridstep))
60
+ gl.xlabel_style = {'size': 10}
61
+ gl.ylabel_style = {'size': 10}
62
+
63
+ return fig, axes.flatten()
64
+
65
+ def plot_map(
66
+ figsize: tuple[float, float] = (8, 8),
67
+ west: float = 100,
68
+ east: float = 137,
69
+ south: float = 16,
70
+ north: float = 54,
71
+ gridlines: bool = True,
72
+ ) -> tuple[mfigure.Figure, maxes.Axes]:
73
+ """
74
+ Plot a map.
75
+ Args:
76
+ figsize: The size of the figure.
77
+ west: The west bound of the map.
78
+ east: The east bound of the map.
79
+ south: The south bound of the map.
80
+ north: The north bound of the map.
81
+ gridlines: Whether to plot gridlines.
82
+ Returns:
83
+ A tuple of the figure and the axes.
84
+ """
85
+ fig, axes = plot_maps(1, 1, figsize, west, east, south, north, gridlines)
86
+ return fig, axes[0]
87
+
88
+ def plot_provinces(axes: maxes.Axes | np.ndarray, file: str = 'JSON/china_provinces.json') -> None:
89
+ """
90
+ Plot the provinces of China on the map.
91
+ Args:
92
+ axes: The axes to plot on.
93
+ file: The file to read the provinces from.
94
+ Returns:
95
+ None.
96
+ """
97
+ provinces = gpd.read_file(file)
98
+ if isinstance(axes, maxes.Axes):
99
+ axes = np.array([axes])
100
+ for ax in axes:
101
+ provinces.boundary.plot(ax = ax, edgecolor = 'gray', linewidth = 0.5, transform = ccrs.PlateCarree())
102
+
103
+ def get_colorbar(
104
+ bounds: list[float] | str = 'O3',
105
+ colors: list[str] | str = 'AQI'
106
+ ) -> tuple[mcolors.ListedColormap, mcolors.BoundaryNorm]:
107
+ """
108
+ Get the color map and the norm for the colorbar.
109
+ Args:
110
+ bounds: The bounds of the colorbar.
111
+ colors: The colors of the colorbar.
112
+ Returns:
113
+ A tuple of the color map and the norm.
114
+ """
115
+ if isinstance(bounds, str):
116
+ if bounds in clb.bounds:
117
+ bounds = clb.bounds[bounds]
118
+ else:
119
+ raise ValueError(f"Invalid bounds: {bounds}")
120
+ if isinstance(colors, str):
121
+ if colors in clb.colors:
122
+ colors = clb.colors[colors]
123
+ else:
124
+ raise ValueError(f"Invalid colors: {colors}")
125
+
126
+ cmap = mcolors.ListedColormap(colors)
127
+ norm = mcolors.BoundaryNorm(bounds, cmap.N)
128
+
129
+ return cmap, norm
130
+
131
+ def plot_colorbar(
132
+ sc: mcollections.PathCollection,
133
+ ax: maxes.Axes = None,
134
+ cax: maxes.Axes = None,
135
+ orientation: str = 'vertical',
136
+ extend: str = 'neither',
137
+ pad: float = 0.02,
138
+ aspect: float = 30,
139
+ fraction: float = 0.02,
140
+ label: str = 'MDA8 (μg $\\cdot$ m$^{-3}$)',
141
+ fontsize: float = 12,
142
+ labelsize: float = 10,
143
+ ) -> None:
144
+ """
145
+ Plot a colorbar.
146
+ Args:
147
+ sc: The scatter plot.
148
+ ax: The axes to plot on.
149
+ cax: The axes to plot the colorbar on.
150
+ orientation: The orientation of the colorbar.
151
+ pad: The padding of the colorbar.
152
+ aspect: The aspect ratio of the colorbar.
153
+ fraction: The fraction of the colorbar.
154
+ label: The label of the colorbar.
155
+ fontsize: The fontsize of the label.
156
+ labelsize: The fontsize of the tick labels.
157
+ Returns:
158
+ None.
159
+ """
160
+ cbar = plt.colorbar(sc, ax = ax, cax = cax, orientation = orientation, extend = extend, pad = pad, aspect = aspect, fraction = fraction)
161
+ cbar.set_label(label, fontsize = fontsize)
162
+ cbar.ax.tick_params(labelsize = labelsize)
163
+
164
+ def save_fig(filename: str, dpi: float = 300, bbox_inches: None | mtransforms.Bbox | str = 'tight') -> None:
165
+ """
166
+ Save the figure.
167
+ Args:
168
+ filename: The filename of the figure.
169
+ dpi: The DPI of the figure.
170
+ bbox_inches: The bounding box inches of the figure.
171
+ Returns:
172
+ None.
173
+ """
174
+ plt.savefig(filename, dpi = dpi, bbox_inches = bbox_inches)
175
+ plt.close()
@@ -0,0 +1,3 @@
1
+ Metadata-Version: 2.4
2
+ Name: geoplotpy
3
+ Version: 0.1.0
@@ -0,0 +1,8 @@
1
+ pyproject.toml
2
+ geoplotpy/__init__.py
3
+ geoplotpy/colorbar.py
4
+ geoplotpy/plot.py
5
+ geoplotpy.egg-info/PKG-INFO
6
+ geoplotpy.egg-info/SOURCES.txt
7
+ geoplotpy.egg-info/dependency_links.txt
8
+ geoplotpy.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ geoplotpy
@@ -0,0 +1,11 @@
1
+ [build-system]
2
+ requires = ["setuptools"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "geoplotpy"
7
+ version = "0.1.0"
8
+
9
+ [tool.setuptools.packages.find]
10
+ where = ["."]
11
+ include = ["geoplotpy"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+