~tfardet/pycafe

837d67646c635ebe27b7f4dc32f902c320b237e3 — Tanguy Fardet 9 months ago a0c9298 improved-plots
add scalebar
3 files changed, 34 insertions(+), 7 deletions(-)

M plot/gisplots.py
M plot/local_deposits.py
M requirements.txt
M plot/gisplots.py => plot/gisplots.py +30 -2
@@ 9,10 9,12 @@ import matplotlib as mpl
import numpy as np
import osmnx as ox

from geopandas import GeoDataFrame
from geopandas import GeoDataFrame, GeoSeries
from matplotlib_scalebar.scalebar import ScaleBar
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
from pandas import DataFrame
from pyproj import CRS, Transformer
from shapely import Point

from gistools.osm.get_geometries import _types, get_all_local_features



@@ 28,8 30,9 @@ def plot_local_admin(
    spatial_bounds: tuple | None = None,
    radius: float | None = None,
    ax: mpl.axes.Axes | None = None,
    colors: Any = None,
    colors: tuple[Any, Any, Any] = None,
    legend: bool = True,
    scalebar: bool = True,
    show: bool = False,
    **kwargs
):


@@ 55,6 58,12 @@ def plot_local_admin(
    ax : matplotlib axis, optional
        Axis on which the plot should be drawn. If None, a new one will be
        created.
    colors : 3-tuple of colors, optional (default: white, gray, black)
        Colors for the pie charts.
    legend : bool, optional (default: True)
        Legend for the nutrient density and pie chart.
    scalebar : bool, optional (default: True)
        Display a scalebar.
    show : bool (default: False)
        Whether to display the plot right away.
    **kwargs : dict


@@ 102,6 111,25 @@ def plot_local_admin(
            _pie_inset(values, keys, p.x, p.y, ax, spatial_bounds, radius,
                       colors, legend, lang, loc, bbta)

    if scalebar:
        distance = 1

        if not boundary.crs.is_projected:
            x, y = boundary.iloc[0].geometry.representative_point().coords[0]
            # Geographic crs
            points = GeoSeries([Point(x, y), Point(x+1, y)], crs=boundary.crs)
            points = points.to_crs(boundary.estimate_utm_crs())

            distance = points[0].distance(points[1])

        ax.add_artist(
            ScaleBar(
                distance,
                box_alpha=0,
                color=kwargs.get("textcolor", "k")
            )
        )


def plot_local_features(area, features=None, ax=None, crs=None, show=False):
    '''

M plot/local_deposits.py => plot/local_deposits.py +3 -5
@@ 253,11 253,13 @@ def plot_map_deposits(
                if (rsum / total_amount) >= limit_deposit or not hide_lowest:
                    rd = np.power(rsum / total_amount, exponent) * max_radius

                    plot_scale = (i==(blen-1))

                    plot_local_admin(r.name, r, data=rdata, pie=pie, radius=rd,
                                     spatial_bounds=bounds, ax=ax,
                                     legend=legend, show_boundary=False,
                                     show=False, language=lang, loc=loc,
                                     bbta=bbta)
                                     bbta=bbta, scale=plot_scale)

                    legend = ax.get_legend() is None



@@ 322,10 324,6 @@ def plot_map_deposits(
            old = ax.get_legend()
            handles = old.legend_handles

            # dark border around handles (not working)
            # for p in handles:
            #     p.set_markeredgecolor("k")

            labels = [l.get_label() for l in handles]
            first_legend = fig.legend(handles, labels, loc=loc,
                                      bbox_to_anchor=bbta,

M requirements.txt => requirements.txt +1 -0
@@ 3,5 3,6 @@

pint-pandas
mapclassify>=2.4
matplotlib_scalebar
orgmatt @ git+https://git.sr.ht/~tfardet/OrgMatt
gistools @ git+https://git.sr.ht/~tfardet/gistools