예제 #1
0
def plot_triplegs(triplegs,
                  out_filename=None,
                  positionfixes=None,
                  staypoints=None,
                  staypoints_radius=None,
                  plot_osm=False):
    """Plots triplegs (optionally to a file).

    Parameters
    ----------
    triplegs : GeoDataFrame
        The triplegs to plot.
    
    out_filename : str
        The file to plot to, if this is not set, the plot will simply be shown.

    positionfixes : GeoDataFrame
        If available, some positionfixes that can additionally be plotted.

    plot_osm : bool
        If this is set to True, it will download an OSM street network and plot 
        below the triplegs.
    """
    _, ax = regular_figure()

    if plot_osm:
        if positionfixes is not None:
            west = positionfixes.geometry.x.min()
            east = positionfixes.geometry.x.max()
            north = positionfixes.geometry.y.max()
            south = positionfixes.geometry.y.min()
        else:
            triplegs_bounds = triplegs.bounds
            west = min(triplegs_bounds.minx
                       ) - 0.03  #TODO: maybe a relative value instead of 0.03
            east = max(triplegs_bounds.maxx) + 0.03
            north = max(triplegs_bounds.maxy) + 0.03
            south = min(triplegs_bounds.miny) - 0.03
        plot_osm_streets(north, south, east, west, ax)

    if positionfixes is not None:
        positionfixes.plot(ax=ax, markersize=0.5, zorder=2)

    if staypoints is not None:
        if staypoints_radius is None:
            staypoints_radius = 3
        for pt in staypoints.to_dict('records'):
            circle = mpatches.Circle((pt.geometry.x, pt.geometry.y),
                                     staypoints_radius,
                                     facecolor='none',
                                     edgecolor='c',
                                     zorder=3)
            ax.add_artist(circle)

    triplegs.plot(ax=ax, cmap='viridis')

    if out_filename is not None:
        save_fig(out_filename, formats=['png'])
    else:
        plt.show()
예제 #2
0
def plot_positionfixes(positionfixes, out_filename=None, plot_osm=False):
    """Plots positionfixes (optionally to a file). If you specify ``plot_osm=True``
    this will use ``osmnx`` to plot streets below the positionfixes. Depending on
    the extent of your data, this might take a long time. 

    Parameters
    ----------
    positionfixes : GeoDataFrame
        The positionfixes to plot.
    
    out_filename : str, optional
        The file to plot to, if this is not set, the plot will simply be shown.

    plot_osm : bool, default False
        If this is set to True, it will download an OSM street network and plot 
        below the staypoints.

    Examples
    --------
    >>> df.as_positionfixes.plot('output.png', plot_osm=True)
    """
    _, ax = regular_figure()

    if plot_osm:
        west = positionfixes['geom'].x.min()
        east = positionfixes['geom'].x.max()
        north = positionfixes['geom'].y.max()
        south = positionfixes['geom'].y.min()
        plot_osm_streets(north, south, east, west, ax)

    positionfixes.plot(ax=ax, markersize=0.5)
    if out_filename is not None:
        save_fig(out_filename, formats=['png'])
    else:
        plt.show()
예제 #3
0
def plot_positionfixes(positionfixes,
                       out_filename=None,
                       plot_osm=False,
                       axis=None):
    """Plots positionfixes (optionally to a file).

    If you specify ``plot_osm=True`` this will use ``osmnx`` to plot streets
    below the positionfixes. Depending on the extent of your data, this might
    take a long time. The data gets transformed to wgs84 for the plotting.

    Parameters
    ----------
    positionfixes : GeoDataFrame (as trackintel positionfixes)
        The positionfixes to plot.

    out_filename : str, optional
        The file to plot to, if this is not set, the plot will simply be shown.

    plot_osm : bool, default False
        If this is set to True, it will download an OSM street network and plot
        below the staypoints.

    axis : matplotlib.pyplot.Artist, optional
        axis on which to draw the plot

    Examples
    --------
    >>> pfs.as_positionfixes.plot('output.png', plot_osm=True)
    """
    if axis is None:
        _, ax = regular_figure()
    else:
        ax = axis
    _, positionfixes = check_gdf_planar(positionfixes, transform=True)

    if plot_osm:
        west = positionfixes.geometry.x.min()
        east = positionfixes.geometry.x.max()
        north = positionfixes.geometry.y.max()
        south = positionfixes.geometry.y.min()
        plot_osm_streets(north, south, east, west, ax)

    positionfixes.plot(ax=ax, markersize=0.5, zorder=2)
    ax.set_aspect("equal", adjustable="box")

    if out_filename is not None:
        save_fig(out_filename, formats=["png"])
    elif axis is None:
        plt.show()
def plot_staypoints(staypoints,
                    out_filename=None,
                    radius=None,
                    positionfixes=None,
                    plot_osm=False):
    """Plots staypoints (optionally to a file). You can specify the radius with which 
    each staypoint should be drawn, as well as if underlying positionfixes and OSM streets
    should be drawn.

    Parameters
    ----------
    staypoints : GeoDataFrame
        The staypoints to plot.
    
    out_filename : str, optional
        The file to plot to, if this is not set, the plot will simply be shown.

    radius : float, optional
        The radius with which circles around staypoints should be drawn.

    positionfixes : GeoDataFrame, optional
        If available, some positionfixes that can additionally be plotted.

    plot_osm : bool, default False
        If this is set to True, it will download an OSM street network and plot 
        below the staypoints.

    Examples
    --------
    >>> df.as_staypoints.plot('output.png', radius=10, positionfixes=pdf, plot_osm=True)
    """
    _, ax = regular_figure()
    name_geocol = staypoints.geometry.name

    if positionfixes is not None:
        west = positionfixes.geometry.x.min() - 0.01
        east = positionfixes.geometry.x.max() + 0.01
        north = positionfixes.geometry.y.max() + 0.01
        south = positionfixes.geometry.y.min() - 0.01
    else:
        west = staypoints.geometry.x.min() - 0.03
        east = staypoints.geometry.x.max() + 0.03
        north = staypoints.geometry.y.max() + 0.03
        south = staypoints.geometry.y.min() - 0.03

    if plot_osm:
        plot_osm_streets(north, south, east, west, ax)

    if positionfixes is not None:
        positionfixes.plot(ax=ax, markersize=0.5, zorder=2)

    if radius is None:
        radius = 5
    for pt in staypoints.to_dict('records'):
        circle = mpatches.Circle((pt[name_geocol].x, pt[name_geocol].y),
                                 radius,
                                 facecolor='none',
                                 edgecolor='g',
                                 zorder=3)
        ax.add_artist(circle)

    ax.set_xlim([west, east])
    ax.set_ylim([south, north])

    if out_filename is not None:
        save_fig(out_filename, formats=['png'])
    else:
        plt.show()
def plot_center_of_locations(locations, out_filename=None, radius=None, positionfixes=None, 
                          staypoints=None, staypoints_radius=None, plot_osm=False):
    """Plots locations (optionally to a file). Optionally, you can specify several other
    datasets to be plotted beneath the locations.

    Parameters
    ----------
    locations : GeoDataFrame
        The locations to plot.
    
    out_filename : str, optional
        The file to plot to, if this is not set, the plot will simply be shown.

    radius : float, optional
        The radius with which circles around locations should be drawn.

    positionfixes : GeoDataFrame, optional
        If available, some positionfixes that can additionally be plotted.

    staypoints : GeoDataFrame, optional
        If available, some staypoints that can additionally be plotted.

    plot_osm : bool, default False
        If this is set to True, it will download an OSM street network and plot 
        below the staypoints.

    Examples
    --------
    >>> df.as_locations.plot('output.png', radius=10, positionfixes=pdf, 
    >>>                   staypoints=spf, staypoints_radius=8, plot_osm=True)
    """
    _, ax = regular_figure()

    if plot_osm:
        if positionfixes is not None:
            west = positionfixes.geometry.x.min()
            east = positionfixes.geometry.x.max()
            north = positionfixes.geometry.y.max()
            south = positionfixes.geometry.y.min()
        else:
            west = locations['center'].x.min() - 0.03
            east = locations['center'].x.max() + 0.03
            north = locations['center'].y.max() + 0.03
            south = locations['center'].y.min() - 0.03
        plot_osm_streets(north, south, east, west, ax)

    if positionfixes is not None:
        positionfixes.plot(ax=ax, markersize=0.5, zorder=2)

    if staypoints is not None:
        if staypoints_radius is None:
            staypoints_radius = 3
        for pt in staypoints.to_dict('records'):
            circle = mpatches.Circle((pt.geometry.x, pt.geometry.y), staypoints_radius,
                                     facecolor='none', edgecolor='c', zorder=3)
            ax.add_artist(circle)

    if radius is None:
        radius = 5
    for pt in locations.to_dict('records'):
        circle = mpatches.Circle((pt['center'].x, pt['center'].y), radius, 
                                  facecolor='none', edgecolor='r', zorder=4)
        ax.add_artist(circle)
    if out_filename is not None:
        save_fig(out_filename, formats=['png'])
    else:
        plt.show()
예제 #6
0
def plot_staypoints(staypoints, out_filename=None, radius=100, positionfixes=None, plot_osm=False, axis=None):
    """Plot staypoints (optionally to a file).

    You can specify the radius with which  each staypoint should be drawn, as well as
    if underlying positionfixes and OSM streets should be drawn. The data gets transformed
    to wgs84 for the plotting.

    Parameters
    ----------
    staypoints : GeoDataFrame (as trackintel staypoints)
        The staypoints to plot.

    out_filename : str, optional
        The file to plot to, if this is not set, the plot will simply be shown.

    radius : float, default 100 (meter)
        The radius in meter with which circles around staypoints should be drawn.

    positionfixes : GeoDataFrame (as trackintel positionfixes), optional
        If available, some positionfixes that can additionally be plotted.

    plot_osm : bool, default False
        If this is set to True, it will download an OSM street network and plot
        below the staypoints.

    axis : matplotlib.pyplot.Artist, optional
        axis on which to draw the plot

    Examples
    --------
    >>> stps.as_staypoints.plot('output.png', radius=100, positionfixes=pfs, plot_osm=True)
    """
    if axis is None:
        _, ax = regular_figure()
    else:
        ax = axis
    name_geocol = staypoints.geometry.name
    _, staypoints = check_gdf_crs(staypoints, transform=True)

    if positionfixes is not None:
        positionfixes.as_positionfixes.plot(plot_osm=plot_osm, axis=ax)
    else:
        west = staypoints.geometry.x.min() - 0.03
        east = staypoints.geometry.x.max() + 0.03
        north = staypoints.geometry.y.max() + 0.03
        south = staypoints.geometry.y.min() - 0.03
        if plot_osm:
            plot_osm_streets(north, south, east, west, ax)
        ax.set_xlim([west, east])
        ax.set_ylim([south, north])

    center_latitude = (ax.get_ylim()[0] + ax.get_ylim()[1]) / 2
    radius = meters_to_decimal_degrees(radius, center_latitude)
    for pt in staypoints.to_dict("records"):
        circle = mpatches.Circle(
            (pt[name_geocol].x, pt[name_geocol].y), radius, facecolor="none", edgecolor="g", zorder=3
        )
        ax.add_artist(circle)

    ax.set_aspect("equal", adjustable="box")
    if out_filename is not None:
        save_fig(out_filename, formats=["png"])
    elif axis is None:
        plt.show()
예제 #7
0
def plot_triplegs(triplegs,
                  out_filename=None,
                  positionfixes=None,
                  staypoints=None,
                  staypoints_radius=100,
                  plot_osm=False,
                  axis=None):
    """Plot triplegs (optionally to a file).

    You can specify several other datasets to be plotted beneath the triplegs,
    as well as if the OSM streets should be drawn. The data gets transformed to
    wgs84 for the plotting.

    Parameters
    ----------
    triplegs : GeoDataFrame (as trackintel triplegs)
        The triplegs to plot.

    out_filename : str, optional
        The file to plot to, if this is not set, the plot will simply be shown.

    positionfixes : GeoDataFrame (as trackintel positionfixes), optional
        If available, some positionfixes that can additionally be plotted.

    staypoints : GeoDataFrame (as trackintel staypoints), optional
        If available, some staypoints that can additionally be plotted.

    staypoints_radius : float, default 100 (meter)
        The radius in meter with which circles around staypoints should be drawn.

    plot_osm : bool, default False
        If this is set to True, it will download an OSM street network and plot
        below the triplegs.

    axis : matplotlib.pyplot.Artist, optional
        axis on which to draw the plot

    Example
    -------
    >>> tpls.as_triplegs.plot('output.png', positionfixes=pfs, staypoints=sp, plot_osm=True)
    """
    if axis is None:
        _, ax = regular_figure()
    else:
        ax = axis
    _, triplegs = check_gdf_planar(triplegs, transform=True)

    if staypoints is not None:
        staypoints.as_staypoints.plot(radius=staypoints_radius,
                                      positionfixes=positionfixes,
                                      plot_osm=plot_osm,
                                      axis=ax)
    elif positionfixes is not None:
        positionfixes.as_positionfixes.plot(plot_osm=plot_osm, axis=ax)
    elif plot_osm:
        triplegs_bounds = triplegs.bounds
        west = min(triplegs_bounds.minx
                   ) - 0.03  # TODO: maybe a relative value instead of 0.03
        east = max(triplegs_bounds.maxx) + 0.03
        north = max(triplegs_bounds.maxy) + 0.03
        south = min(triplegs_bounds.miny) - 0.03
        plot_osm_streets(north, south, east, west, ax)

    triplegs.plot(ax=ax, cmap="viridis")
    ax.set_aspect("equal", adjustable="box")

    if out_filename is not None:
        save_fig(out_filename, formats=["png"])
    else:
        plt.show()
예제 #8
0
def plot_center_of_locations(
    locations,
    out_filename=None,
    radius=None,
    positionfixes=None,
    staypoints=None,
    staypoints_radius=None,
    plot_osm=False,
    axis=None,
):
    """Plot locations (optionally to a file).

    Optionally, you can specify several other datasets to be plotted beneath the locations.

    Parameters
    ----------
    locations : GeoDataFrame (as trackintel locations)
        The locations to plot.

    out_filename : str, optional
        The file to plot to, if this is not set, the plot will simply be shown.

    radius : float, optional
        The radius in meter with which circles around locations should be drawn.

    positionfixes : GeoDataFrame (as trackintel positionfixes), optional
        If available, some positionfixes that can additionally be plotted.

    staypoints : GeoDataFrame (as trackintel staypoints), optional
        If available, some staypoints that can additionally be plotted.

    staypoints_radius : float, optional
        The radius in meter with which circles around staypoints should be drawn.

    plot_osm : bool, default False
        If this is set to True, it will download an OSM street network and plot
        below the staypoints.

    axis : matplotlib.pyplot.Artist, optional
        axis on which to draw the plot

    Examples
    --------
    >>> df.as_locations.plot('output.png', radius=100, positionfixes=pdf,
    >>>                      staypoints=spf, staypoints_radius=80, plot_osm=True)
    """
    if axis is None:
        _, ax = regular_figure()
    else:
        ax = axis
    locations = transform_gdf_to_wgs84(locations)

    if staypoints is not None:
        staypoints.as_staypoints.plot(radius=staypoints_radius,
                                      positionfixes=positionfixes,
                                      plot_osm=plot_osm,
                                      axis=ax)
    elif positionfixes is not None:
        positionfixes.as_positionfixes.plot(plot_osm=plot_osm, axis=ax)
    elif plot_osm:
        west = locations["center"].x.min() - 0.03
        east = locations["center"].x.max() + 0.03
        north = locations["center"].y.max() + 0.03
        south = locations["center"].y.min() - 0.03
        plot_osm_streets(north, south, east, west, ax)

    if radius is None:
        radius = 125
    center_latitude = (ax.get_ylim()[0] + ax.get_ylim()[1]) / 2
    radius = meters_to_decimal_degrees(radius, center_latitude)
    for pt in locations.to_dict("records"):
        circle = mpatches.Circle((pt["center"].x, pt["center"].y),
                                 radius,
                                 facecolor="none",
                                 edgecolor="r",
                                 zorder=4)
        ax.add_artist(circle)
    if out_filename is not None:
        save_fig(out_filename, formats=["png"])
    else:
        plt.show()