Skip to main content

Tools for plotting routes, clusters and more from JSON

Project description

nextplot

pypi_versionbuild

Tools for plotting routes and clusters from JSON

Installation

pip install nextplot

Usage

If the installation succeeded, you should be able to invoke the following:

nextplot --help

Furthermore, use the route and cluster commands for the respective plotting type. Find an overview of the arguments for the specific mode by invoking nextplot route --help and nextplot cluster --help.

Above shows some information about how to use the script. Below presents some further information for running the script using route plotting as an example.

There are basically two options of running the script. Either feed the JSON to STDIN of the script like so:

cat examples/data/kyoto-route.json | nextplot route \
  --jpath_route "vehicles[*].route" \
  --jpath_x "position.lon" \
  --jpath_y "position.lat"

Or supply a path to the .json file like so:

nextplot route \
  --input_route examples/data/kyoto-route.json \
  --jpath_route "vehicles[*].route" \
  --jpath_x "position.lon" \
  --jpath_y "position.lat"

Both approaches will create a .png plot image and if possible (valid lon/lat coordinates given) an interactive .html plot file. The filenames will be plot.[png,html] for the first option, based on the input filename for the second option and customized ones if --output_image and/or --output_map are specified.

The input file is expected to have some JSON array of positions which can be addressed using the notation described here: https://goessner.net/articles/JsonPath/. The path to the positions can be modified via the --jpath_route parameter. For example, if your input file stores the locations like shown below, the path "vehicles[*].route" will extract them. As you can see, the path first goes through the vehicles. Next, [*] denotes that a list of vehicles is expected, which in turn results in a list of routes. Finally, .route points to the exact location of the route object per vehicle. The --jpath_x and --jpath_y parameters are used to extract the longitude and latitude values from the stop objects at position.lon and position.lat.

{
    "vehicles": [
        // ...
        {
            "id": "v1",
            "route": [
                {
                    "id": "v1-start",
                    "position": { "lon": 135.73723, "lat": 35.04381 }
                },
                {
                    "id": "Kinkaku-ji",
                    "position": { "lon": 135.728898, "lat": 35.039705 }
                },
                {
                    "id": "Nijō Castle",
                    "position": { "lon": 135.748134, "lat": 35.014239 }
                },
                {
                    "id": "Arashiyama Bamboo Forest",
                    "position": { "lon": 135.672009, "lat": 35.017209 }
                }
            ]
        }
        // ...
    ]
}

Further examples

A more detailed introduction and a plot gallery can be found here.

Preview

Preview route plot (screenshot of .html-file, cartodbdark_matter selected):

sample-popup

Another preview route plot (screenshot of .html-file, cartodbdark_matter selected):

sample-plot-html

Preview cluster plot (screenshot of .html-file, cartodbdark_matter selected):

sample-plot-html

Auto-completion

Auto-completion (using tab) is supported via argcomplete. To enable it, install the package:

pip install argcomplete

Then, add the following line to your ~/.bashrc:

eval "$(register-python-argcomplete nextplot)"

Tests

Tests are located in tests/ and can be run via python -m pytest. Update test expectations (golden files) by running UPDATE=1 python test_cli.py from the test directory. Tests require specific versions of the dependencies to be installed. These can be installed via pip install -r requirements-dev.txt. It is recommended to update the expectations in a docker container to avoid messing up local dependencies. This can be done by running the following commands:

docker run --rm -it -v $(pwd):/app -w /app python:3.11 bash -c "pip install -r requirements-dev.txt && cd tests && UPDATE=1 python test_cli.py"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nextplot-0.1.9.tar.gz (5.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nextplot-0.1.9-py3-none-any.whl (46.0 kB view details)

Uploaded Python 3

File details

Details for the file nextplot-0.1.9.tar.gz.

File metadata

  • Download URL: nextplot-0.1.9.tar.gz
  • Upload date:
  • Size: 5.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nextplot-0.1.9.tar.gz
Algorithm Hash digest
SHA256 004c0dfbf48876e59a01760f473aa81a3a1bc7cd81d51a29225a937d56e33846
MD5 1ef716d2adc79aefbfad96cfaa3a7f0f
BLAKE2b-256 a42a2e75de6d65b3ce07651ec9aa5c66871e2b2bc12d6f036018d678d408bd85

See more details on using hashes here.

Provenance

The following attestation bundles were made for nextplot-0.1.9.tar.gz:

Publisher: release.yml on nextmv-io/nextplot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nextplot-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: nextplot-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 46.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nextplot-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 b67d6fdd1345c86f576c1367fd390b3f8115703ddf178e47759db519c60d3f1f
MD5 762ca42978595a183fbac625c48e6222
BLAKE2b-256 7f249396d48e1ef33a959e7a307c7ea6b32f3c404a7dde04f26de5353d185483

See more details on using hashes here.

Provenance

The following attestation bundles were made for nextplot-0.1.9-py3-none-any.whl:

Publisher: release.yml on nextmv-io/nextplot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page