Skip to main content

Digitize plots and extract trajectories.

Project description

Build Status PyPI version

PlotDigitizer

A python3 script to digitize plot.

Usage

  1. Remove all the text from the image. Only axis and plot should be left.

For example, following image is from MacFadden and Koshland, PNAS 1990.

It should be trimmed. Remove the top border. You can use gimp or imagemagick or gthumb or any other tool for cropping.

  1. Then we run the script like this.
./plotdigitizer.py -i ./figures/trimmed.png -p 0,0 -p 10,0 -p 0,1

Option -i accepts the input file.

We need three -p (points) to map the coordinates onto the pixels of the image. In the example above, we have given three coordinates: 0,0 (where x-axis and y-axis intesect) , 20,0 (a point on x-axis) and 0,1 (a point on y-axis). To map thse points on the pixels, we are going to click on the image to locate these coordinates later. Make sure to click in the same order.

  1. The data-points will be dumped to a csv file. If --plot output.png is passed, it will also plot the computed data-points to output.png. This requires matplotlib.

Notice the errors near the boxes; since we have not trimmed them.

Mapping coordinates at command line (batch mode)

There is subtle difference here. Most plots use bottom left corner of the image as (0,0) while the opencv library (which we are using in this project) top-left corner is mapped to (0,0). This may cause subtle effects if you are not careful when passing values of location manually. See issue #1 for discussion. I got these values from program gimp.

./plotdigitizer.py -i ./figures/trimmed.png -p 0,0 -p 20,0 -p 0,1 \
    -l 22,295 -l 142,295 -l 22,215 --plot output.png

Dependencies

Install Python bindings of opencv manually. On ubuntu box, it is available in official repositories ie., $ sudo apt install python3-opencv. You can also use the Python wheel available here https://pypi.org/project/opencv-python/ e.g. $ pip install opencv-python --user.

Limitations

Currently this script has following limitations:

  • Background must not be transparent. It might work with transparent background but I've not tested it.
  • Only b/w images are supported for now. Color images will be converted to grayscale upon reading.
  • One image should have only one trajectory.

You might be interested in more versatile WebPlotDigitizer by Ankit Rohatagi.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

PlotDigitizer-0.1.0-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file PlotDigitizer-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: PlotDigitizer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for PlotDigitizer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 daae74be1f0239e1a7d2dce228577e33595c650561fbaa55ee5cc1df8f24abf1
MD5 2b4aa2e965940523645822d4612f2b6b
BLAKE2b-256 8fe5bb4953803e85a4f553727d36dfa8869435207c262d0b08c1ddc4af0c80dd

See more details on using hashes here.

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