def weighted_pointmap_wkb_2(point, c, s, conf=vega): from arctern import weighted_point_map_layer return weighted_point_map_layer(conf, point, False, color_weights=c, size_weights=s)
def test_weighted_point_map(): x_data = [] y_data = [] c_data = [] s_data = [] x_data.append(-73.96524) x_data.append(-73.96118) x_data.append(-73.97324) x_data.append(-73.98456) y_data.append(40.73747) y_data.append(40.74507) y_data.append(40.75890) y_data.append(40.77654) c_data.append(1) c_data.append(2) c_data.append(3) c_data.append(4) s_data.append(4) s_data.append(6) s_data.append(8) s_data.append(10) arr_x = pandas.Series(x_data) arr_y = pandas.Series(y_data) points = arctern.ST_Point(arr_x, arr_y) arr_c = pandas.Series(c_data) arr_s = pandas.Series(s_data) vega1 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF"], opacity=1.0, coordinate_system="EPSG:4326") res1 = arctern.weighted_point_map_layer(vega1, points) save_png(res1, "/tmp/test_weighted_0_0.png") vega2 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF", "#FF0000"], color_bound=[1, 5], opacity=1.0, coordinate_system="EPSG:4326") res2 = arctern.weighted_point_map_layer(vega2, points, color_weights=arr_c) save_png(res2, "/tmp/test_weighted_1_0.png") vega3 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF"], size_bound=[1, 10], opacity=1.0, coordinate_system="EPSG:4326") res3 = arctern.weighted_point_map_layer(vega3, points, size_weights=arr_s) save_png(res3, "/tmp/test_weighted_0_1.png") vega4 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF", "#FF0000"], color_bound=[1, 5], size_bound=[1, 10], opacity=1.0, coordinate_system="EPSG:4326") res4 = arctern.weighted_point_map_layer(vega4, points, color_weights=arr_c, size_weights=arr_s) save_png(res4, "/tmp/test_weighted_1_1.png")
def weighted_pointmap(ax, points, color_weights=None, size_weights=None, bounding_box=None, color_gradient=["#115f9a", "#d0f400"], color_bound=[0, 0], size_bound=[3], opacity=1.0, coordinate_system='EPSG:3857', **extra_contextily_params): """ :type ax: AxesSubplot :param ax: Matplotlib axes object on which to add the basemap. :type points: Series(dtype: object) :param points: Points in WKB form :type bounding_box: (float, float, float, float) :param bounding_box: The bounding rectangle, as a [left, upper, right, lower]-tuple. value should be of :coordinate_system: :type point_szie: int :param point_size: size of point :type opacity: float :param opacity: opacity of point :type coordinate_system: str :param coordinate_system: either 'EPSG:4326' or 'EPSG:3857' :type extra_contextily_params: dict :param extra_contextily_params: extra parameters for contextily.add_basemap. See https://contextily.readthedocs.io/en/latest/reference.html """ from matplotlib import pyplot as plt import contextily as cx bbox = _transform_bbox(bounding_box, coordinate_system, 'epsg:3857') w, h = _get_recom_size(bbox[2] - bbox[0], bbox[3] - bbox[1]) vega = vega_weighted_pointmap(w, h, bounding_box=bounding_box, color_gradient=color_gradient, color_bound=color_bound, size_bound=size_bound, opacity=opacity, coordinate_system=coordinate_system) hexstr = arctern.weighted_point_map_layer(vega, points, color_weights=color_weights, size_weights=size_weights) f = io.BytesIO(base64.b64decode(hexstr)) img = plt.imread(f) ax.set(xlim=(bbox[0], bbox[2]), ylim=(bbox[1], bbox[3])) cx.add_basemap(ax, **extra_contextily_params) ax.imshow(img, alpha=img[:, :, 3], extent=(bbox[0], bbox[2], bbox[1], bbox[3]))
def weighted_pointmap(ax, points, color_weights=None, size_weights=None, bounding_box=None, color_gradient=["#115f9a", "#d0f400"], color_bound=[0, 0], size_bound=[3], opacity=1.0, coordinate_system='EPSG:3857', **extra_contextily_params): """ Plot weighted pointmap in Matplotlib :type ax: AxesSubplot :param ax: Matplotlib axes object on which to add the basemap. :type points: GeoSeries :param points: Sequence of Points :type color_weights: Series(dtype: float|int64) :param color_weights: Weights for point color, default as None :type size_weights: Series(dtype: float|int64) :param size_weights: Weights for point size, deciding diameter of point (after bounded by size_bound) Default as None :type bounding_box: list :param bounding_box: Specify the bounding rectangle [west, south, east, north], Default as None :type color_gradient: list :param color_gradient: Specify range of color gradient. Either use ["hex_color"] to specify a same color for all points, or ["hex_color1", "hex_color2"] to specify a color gradient ranging from "hex_color1" to "hex_color2" Default as ["#115f9a", "#d0f400"] :type color_bound: list :param color_bound: Specify weight range [w1, w2] binding to color_gradient. Needed only when color_gradient has two value ["color1", "color2"]. Bind w1 to "color1", and w2 to "color2". When weight < w1 or weight > w2, truncate to w1/w2 accordingly. Default as [0, 0] :type size_bound: list :param size_bound: Specify range [w1, w2] of size_weights. When weight < w1 or weight > w2, truncate to w1/w2 accordingly. Default as [3] :type opacity: float :param opacity: Opacity of point, ranged from 0.0 to 1.0, default as 1.0 :type coordinate_system: str :param coordinate_system: Coordinate Reference System of the geometry objects. Must be SRID formed, e.g. 'EPSG:4326' or 'EPSG:3857' Default as 'EPSG:3857' :type extra_contextily_params: dict :param extra_contextily_params: Extra parameters will be passed to contextily.add_basemap. See https://contextily.readthedocs.io/en/latest/reference.html for details :example: >>> import pandas as pd >>> import numpy as np >>> import arctern >>> import matplotlib.pyplot as plt >>> # read from test.csv >>> # Download link: https://raw.githubusercontent.com/arctern-io/arctern-resources/benchmarks/benchmarks/dataset/layer_rendering_test_data/test_data.csv >>> df = pd.read_csv("/path/to/test_data.csv", dtype={'longitude':np.float64, 'latitude':np.float64, 'color_weights':np.float64, 'size_weights':np.float64, 'region_boundaries':np.object}) >>> points = arctern.GeoSeries.point(df['longitude'], df['latitude']) >>> >>> # plot weighted pointmap with variable color and fixed size >>> fig, ax = plt.subplots(figsize=(10, 6), dpi=200) >>> arctern.plot.weighted_pointmap(ax, points, color_weights=df['color_weights'], bounding_box=[-73.99668712186558,40.72972339069935,-73.99045479584949,40.7345193345495], color_gradient=["#115f9a", "#d0f400"], color_bound=[2.5,15], size_bound=[16], opacity=1.0, coordinate_system="EPSG:4326") >>> plt.show() >>> >>> # plot weighted pointmap with fixed color and variable size >>> fig, ax = plt.subplots(figsize=(10, 6), dpi=200) >>> arctern.plot.weighted_pointmap(ax, points, size_weights=df['size_weights'], bounding_box=[-73.99668712186558,40.72972339069935,-73.99045479584949,40.7345193345495], color_gradient=["#37A2DA"], size_bound=[15, 50], opacity=1.0, coordinate_system="EPSG:4326") >>> plt.show() >>> >>> # plot weighted pointmap with variable color and size >>> fig, ax = plt.subplots(figsize=(10, 6), dpi=200) >>> arctern.plot.weighted_pointmap(ax, points, color_weights=df['color_weights'], size_weights=df['size_weights'], bounding_box=[-73.99668712186558,40.72972339069935,-73.99045479584949,40.7345193345495], color_gradient=["#115f9a", "#d0f400"], color_bound=[2.5,15], size_bound=[15, 50], opacity=1.0, coordinate_system="EPSG:4326") >>> plt.show() """ from matplotlib import pyplot as plt import contextily as cx bbox = _transform_bbox(bounding_box, coordinate_system, 'epsg:3857') w, h = _get_recom_size(bbox[2] - bbox[0], bbox[3] - bbox[1]) vega = vega_weighted_pointmap(w, h, bounding_box=bounding_box, color_gradient=color_gradient, color_bound=color_bound, size_bound=size_bound, opacity=opacity, coordinate_system=coordinate_system) hexstr = arctern.weighted_point_map_layer(vega, points, color_weights=color_weights, size_weights=size_weights) f = io.BytesIO(base64.b64decode(hexstr)) img = plt.imread(f) ax.set(xlim=(bbox[0], bbox[2]), ylim=(bbox[1], bbox[3])) cx.add_basemap(ax, **extra_contextily_params) ax.imshow(img, alpha=img[:, :, 3], extent=(bbox[0], bbox[2], bbox[1], bbox[3])) ax.axis('off')
def weighted_pointmap(ax, points, color_weights=None, size_weights=None, bounding_box=None, color_gradient=["#115f9a", "#d0f400"], color_bound=[0, 0], size_bound=[3], opacity=1.0, coordinate_system='EPSG:3857', **extra_contextily_params): """ Plots a weighted point map in Matplotlib. Parameters ---------- ax : matplotlib.axes.Axes Axes where geometries will be plotted. points : GeoSeries Sequence of points. color_weights : Series, optional Weights of point color. size_weights : Series, optional Weights of point size. bounding_box : list Bounding box of the map. For example, [west, south, east, north]. color_gradient : list, optional Range of color gradient, by default ["#115f9a", "#d0f400"]. Either use ["hex_color"] to specify a same color for all geometries, or ["hex_color1", "hex_color2"] to specify a color gradient ranging from "hex_color1" to "hex_color2". color_bound : list, optional Weight range [w1, w2] of ``color_gradient``, by default [0, 0]. Needed only when ``color_gradient`` has two values ["color1", "color2"]. Binds w1 to "color1", and w2 to "color2". When weight < w1 or weight > w2, the weight will be truncated to w1 or w2 accordingly. size_bound : list, optional Weight range [w1, w2] of ``size_weights``, by default [3]. When weight < w1 or weight > w2, the weight will be truncated to w1 or w2 accordingly. opacity : float, optional Opacity of points, ranged from 0.0 to 1.0, by default 1.0. coordinate_system : str, optional The Coordinate Reference System (CRS) set to all geometries, by default 'EPSG:3857'. Only supports SRID as a WKT representation of CRS by now. **extra_contextily_params: dict Extra parameters passed to `contextily.add_basemap. <https://contextily.readthedocs.io/en/latest/reference.html>`_ Examples ------- >>> import pandas as pd >>> import numpy as np >>> import arctern >>> import matplotlib.pyplot as plt >>> # read from test.csv >>> # Download link: https://raw.githubusercontent.com/arctern-io/arctern-resources/benchmarks/benchmarks/dataset/layer_rendering_test_data/test_data.csv >>> df = pd.read_csv("/path/to/test_data.csv", dtype={'longitude':np.float64, 'latitude':np.float64, 'color_weights':np.float64, 'size_weights':np.float64, 'region_boundaries':np.object}) >>> points = arctern.GeoSeries.point(df['longitude'], df['latitude']) >>> >>> # plot weighted pointmap with variable color and fixed size >>> fig, ax = plt.subplots(figsize=(10, 6), dpi=200) >>> arctern.plot.weighted_pointmap(ax, points, color_weights=df['color_weights'], bounding_box=[-73.99668712186558,40.72972339069935,-73.99045479584949,40.7345193345495], color_gradient=["#115f9a", "#d0f400"], color_bound=[2.5,15], size_bound=[16], opacity=1.0, coordinate_system="EPSG:4326") >>> plt.show() >>> >>> # plot weighted pointmap with fixed color and variable size >>> fig, ax = plt.subplots(figsize=(10, 6), dpi=200) >>> arctern.plot.weighted_pointmap(ax, points, size_weights=df['size_weights'], bounding_box=[-73.99668712186558,40.72972339069935,-73.99045479584949,40.7345193345495], color_gradient=["#37A2DA"], size_bound=[15, 50], opacity=1.0, coordinate_system="EPSG:4326") >>> plt.show() >>> >>> # plot weighted pointmap with variable color and size >>> fig, ax = plt.subplots(figsize=(10, 6), dpi=200) >>> arctern.plot.weighted_pointmap(ax, points, color_weights=df['color_weights'], size_weights=df['size_weights'], bounding_box=[-73.99668712186558,40.72972339069935,-73.99045479584949,40.7345193345495], color_gradient=["#115f9a", "#d0f400"], color_bound=[2.5,15], size_bound=[15, 50], opacity=1.0, coordinate_system="EPSG:4326") >>> plt.show() """ from matplotlib import pyplot as plt import contextily as cx bbox = _transform_bbox(bounding_box, coordinate_system, 'epsg:3857') w, h = _get_recom_size(bbox[2] - bbox[0], bbox[3] - bbox[1]) vega = vega_weighted_pointmap(w, h, bounding_box=bounding_box, color_gradient=color_gradient, color_bound=color_bound, size_bound=size_bound, opacity=opacity, coordinate_system=coordinate_system) hexstr = arctern.weighted_point_map_layer(vega, points, color_weights=color_weights, size_weights=size_weights) f = io.BytesIO(base64.b64decode(hexstr)) img = plt.imread(f) ax.set(xlim=(bbox[0], bbox[2]), ylim=(bbox[1], bbox[3])) cx.add_basemap(ax, **extra_contextily_params) ax.imshow(img, alpha=img[:, :, 3], extent=(bbox[0], bbox[2], bbox[1], bbox[3])) ax.axis('off')
def weighted_pointmap_wkb_0(point, conf=vega): from arctern import weighted_point_map_layer return weighted_point_map_layer(conf, point, False)
def weighted_pointmap_wkb_3857_1(point, c, conf=vega): from arctern import weighted_point_map_layer return weighted_point_map_layer(conf, point, False, color_weights=c)