plotdigitizer


Nameplotdigitizer JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://github.com/dilawar/PlotDigitizer
SummaryExtract raw data from plots images
upload_time2024-07-14 18:21:53
maintainerDilawar Singh
docs_urlNone
authorDilawar Singh
requires_python<=4,>=3.9
licenseLGPL-3.0-or-later
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![Python application](https://github.com/dilawar/PlotDigitizer/workflows/Python%20application/badge.svg) [![PyPI version](https://badge.fury.io/py/plotdigitizer.svg)](https://badge.fury.io/py/plotdigitizer) [![DOI](https://zenodo.org/badge/140683649.svg)](https://zenodo.org/badge/latestdoi/140683649)

A Python3 command line utility to digitize plots in batch mode.

This utility is useful when you have a lot of similar plots such as EEG, ECG recordings. See examples below.

For one-off use cases, you will find web-based digitizer [WebPlotDigitizer](https://automeris.io/WebPlotDigitizer/) 
by Ankit Rohatagi much more easier to use.

## Installation

```
$ python3 -m pip install plotdigitizer
$ plotdigitizer --help
```

## Preparing image

Crop the image and leave only axis and trajectories. I use
`gthumb` utility on Linux. You can also use imagemagick or gimp.

Following image is from MacFadden and Koshland, PNAS 1990 after trimming. One
can also remove top and right axis.

![Trimmed image](./figures/trimmed.png)

__Run__

```bash
plotdigitizer ./figures/trimmed.png -p 0,0 -p 10,0 -p 0,1
```

We need at least three points (`-p` option) to map axes onto the image.  In the example
above, these are `0,0` (where x-axis and y-axis intesect) , `10,0` (a point on
x-axis) and `0,1` (a point on y-axis). To map these points on the image, you
will be asked to click on these points on the image. _Make sure to click in
the same order and click on the points as precisely as you could. Any error in
this step will propagate._ If you don't have `0,0` in your image, you have to provide
4 points: 2 on x-axis and 2 on y-axis.

The data-points will be dumped to a csv file specified by __`--output
/path/to/file.csv`__.

If `--plot output.png` is passed, a plot of the extracted data-points will be
saved to `output.png`. This requires `matplotlib`. Very useful when debugging/testing.

![](./figures/traj.png)

Notice the error near the right y-axis.

## Using in batch mode

You can pass the coordinates of points in the image at the command prompt.
This allows to run in the batch mode without any need for the user to click on
the image.

```bash
plotdigitizer ./figures/trimmed.png -p 0,0 -p 20,0 -p 0,1 -l 22,295 -l 142,295 -l 22,215 --plot output.png
```

### How to find coordinates of axes points

In the example above, point `0,0` is mapped to coordinate `22,295` i.e., the
data point `0,0` is on the 22nd row and 295th column of the image (_assuming that bottom left
of the image is first row, first column `(0,0)`_). I have included an utility
`plotdigitizer-locate` (script `plotdigitizer/locate.py`) which you can use to
find the coordinates of points.


```bash
$ plotdigitizer-locate figures/trimmed.png
```

or, by directly using the script:

```bash
$ python3 plotdigitizer/locate.py figures/trimmed.png
```

This command opens the image in a simple window. You can click on a point and
its coordinate will be written on the image itself. Note them down.

![](./figures/trimmed_locate.png)


# Examples


### Base examples

```bash
plotdigitizer figures/graphs_1.png \
		-p 1,0 -p 6,0 -p 0,3 \
		-l 165,160 -l 599,160 -l 85,60 \
		--plot figures/graphs_1.result.png \
		--preprocess
```

![original](./figures/graphs_1.png)
![reconstructed](./figures/graphs_1.result.png)

### Light grids

```
plotdigitizer  figures/ECGImage.png \
		-p 1,0 -p 5,0 -p 0,1 \
        -l 290,337 -l 1306,338 -l 106,83 \
		--plot figures/ECGImage.result.png
```

![original](./figures/ECGImage.png)
![reconstructed](./figures/ECGImage.result.png)

### With grids

```
plotdigitizer  figures/graph_with_grid.png \
		-p 200,0 -p 1000,0 -p 0,50 \
        -l 269,69 -l 1789,69 -l 82,542 \
		--plot figures/graph_with_grid.result.png
```

![original](./figures/graph_with_grid.png)
_Image credit: Yang yi, Wang_

![reconstructed](./figures/graph_with_grid.result.png)

__Note that legend was not removed in the original figure and it has screwed up
the detection below it.__

# Limitations

This application has following limitations:

- Only b/w images are supported for now. Color images will be converted to grayscale upon reading.
- Each plot should have only one trajectory.

## Need help

Open an issue and please attach the sample plot.

## Related Projects

1.  [WebPlotDigitizer](https://automeris.io/WebPlotDigitizer/) by Ankit
Rohatagi is very versatile.


## Notes

- grapvhiz version 2.47.2 is broken for some xml files. See
<https://forum.graphviz.org/t/assert-sz-2-in-convertsptoroute/689>. Please use a
different version.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dilawar/PlotDigitizer",
    "name": "plotdigitizer",
    "maintainer": "Dilawar Singh",
    "docs_url": null,
    "requires_python": "<=4,>=3.9",
    "maintainer_email": "dilawar.s.rajput@gmail.com",
    "keywords": null,
    "author": "Dilawar Singh",
    "author_email": "dilawar.s.rajput@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ff/80/5d666722c8a078fd41bc57825858791d950e38bdfafbd74a3f04e150e46d/plotdigitizer-0.3.0.tar.gz",
    "platform": null,
    "description": "![Python application](https://github.com/dilawar/PlotDigitizer/workflows/Python%20application/badge.svg) [![PyPI version](https://badge.fury.io/py/plotdigitizer.svg)](https://badge.fury.io/py/plotdigitizer) [![DOI](https://zenodo.org/badge/140683649.svg)](https://zenodo.org/badge/latestdoi/140683649)\n\nA Python3 command line utility to digitize plots in batch mode.\n\nThis utility is useful when you have a lot of similar plots such as EEG, ECG recordings. See examples below.\n\nFor one-off use cases, you will find web-based digitizer [WebPlotDigitizer](https://automeris.io/WebPlotDigitizer/) \nby Ankit Rohatagi much more easier to use.\n\n## Installation\n\n```\n$ python3 -m pip install plotdigitizer\n$ plotdigitizer --help\n```\n\n## Preparing image\n\nCrop the image and leave only axis and trajectories. I use\n`gthumb` utility on Linux. You can also use imagemagick or gimp.\n\nFollowing image is from MacFadden and Koshland, PNAS 1990 after trimming. One\ncan also remove top and right axis.\n\n![Trimmed image](./figures/trimmed.png)\n\n__Run__\n\n```bash\nplotdigitizer ./figures/trimmed.png -p 0,0 -p 10,0 -p 0,1\n```\n\nWe need at least three points (`-p` option) to map axes onto the image.  In the example\nabove, these are `0,0` (where x-axis and y-axis intesect) , `10,0` (a point on\nx-axis) and `0,1` (a point on y-axis). To map these points on the image, you\nwill be asked to click on these points on the image. _Make sure to click in\nthe same order and click on the points as precisely as you could. Any error in\nthis step will propagate._ If you don't have `0,0` in your image, you have to provide\n4 points: 2 on x-axis and 2 on y-axis.\n\nThe data-points will be dumped to a csv file specified by __`--output\n/path/to/file.csv`__.\n\nIf `--plot output.png` is passed, a plot of the extracted data-points will be\nsaved to `output.png`. This requires `matplotlib`. Very useful when debugging/testing.\n\n![](./figures/traj.png)\n\nNotice the error near the right y-axis.\n\n## Using in batch mode\n\nYou can pass the coordinates of points in the image at the command prompt.\nThis allows to run in the batch mode without any need for the user to click on\nthe image.\n\n```bash\nplotdigitizer ./figures/trimmed.png -p 0,0 -p 20,0 -p 0,1 -l 22,295 -l 142,295 -l 22,215 --plot output.png\n```\n\n### How to find coordinates of axes points\n\nIn the example above, point `0,0` is mapped to coordinate `22,295` i.e., the\ndata point `0,0` is on the 22nd row and 295th column of the image (_assuming that bottom left\nof the image is first row, first column `(0,0)`_). I have included an utility\n`plotdigitizer-locate` (script `plotdigitizer/locate.py`) which you can use to\nfind the coordinates of points.\n\n\n```bash\n$ plotdigitizer-locate figures/trimmed.png\n```\n\nor, by directly using the script:\n\n```bash\n$ python3 plotdigitizer/locate.py figures/trimmed.png\n```\n\nThis command opens the image in a simple window. You can click on a point and\nits coordinate will be written on the image itself. Note them down.\n\n![](./figures/trimmed_locate.png)\n\n\n# Examples\n\n\n### Base examples\n\n```bash\nplotdigitizer figures/graphs_1.png \\\n\t\t-p 1,0 -p 6,0 -p 0,3 \\\n\t\t-l 165,160 -l 599,160 -l 85,60 \\\n\t\t--plot figures/graphs_1.result.png \\\n\t\t--preprocess\n```\n\n![original](./figures/graphs_1.png)\n![reconstructed](./figures/graphs_1.result.png)\n\n### Light grids\n\n```\nplotdigitizer  figures/ECGImage.png \\\n\t\t-p 1,0 -p 5,0 -p 0,1 \\\n        -l 290,337 -l 1306,338 -l 106,83 \\\n\t\t--plot figures/ECGImage.result.png\n```\n\n![original](./figures/ECGImage.png)\n![reconstructed](./figures/ECGImage.result.png)\n\n### With grids\n\n```\nplotdigitizer  figures/graph_with_grid.png \\\n\t\t-p 200,0 -p 1000,0 -p 0,50 \\\n        -l 269,69 -l 1789,69 -l 82,542 \\\n\t\t--plot figures/graph_with_grid.result.png\n```\n\n![original](./figures/graph_with_grid.png)\n_Image credit: Yang yi, Wang_\n\n![reconstructed](./figures/graph_with_grid.result.png)\n\n__Note that legend was not removed in the original figure and it has screwed up\nthe detection below it.__\n\n# Limitations\n\nThis application has following limitations:\n\n- Only b/w images are supported for now. Color images will be converted to grayscale upon reading.\n- Each plot should have only one trajectory.\n\n## Need help\n\nOpen an issue and please attach the sample plot.\n\n## Related Projects\n\n1.  [WebPlotDigitizer](https://automeris.io/WebPlotDigitizer/) by Ankit\nRohatagi is very versatile.\n\n\n## Notes\n\n- grapvhiz version 2.47.2 is broken for some xml files. See\n<https://forum.graphviz.org/t/assert-sz-2-in-convertsptoroute/689>. Please use a\ndifferent version.\n",
    "bugtrack_url": null,
    "license": "LGPL-3.0-or-later",
    "summary": "Extract raw data from plots images",
    "version": "0.3.0",
    "project_urls": {
        "Homepage": "https://github.com/dilawar/PlotDigitizer",
        "Repository": "https://github.com/dilawar/PlotDigitizer"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6d628094cff50892984857fa6385c078195f2763ee57356985e41006fb7863ae",
                "md5": "35bf5fde4a113428c237d98c68edf2b1",
                "sha256": "0fa2dc3654acaa69c7e457114d504227d328ec214e21234209d6e7905ae8238e"
            },
            "downloads": -1,
            "filename": "plotdigitizer-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "35bf5fde4a113428c237d98c68edf2b1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<=4,>=3.9",
            "size": 24367,
            "upload_time": "2024-07-14T18:21:52",
            "upload_time_iso_8601": "2024-07-14T18:21:52.429399Z",
            "url": "https://files.pythonhosted.org/packages/6d/62/8094cff50892984857fa6385c078195f2763ee57356985e41006fb7863ae/plotdigitizer-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ff805d666722c8a078fd41bc57825858791d950e38bdfafbd74a3f04e150e46d",
                "md5": "dd5a4cdad8fc1be6f485ac08fccb32ba",
                "sha256": "c5b7188c98cfed0033d1e601f72dc189c1cee7412fa374533d9f6c585bb74f16"
            },
            "downloads": -1,
            "filename": "plotdigitizer-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "dd5a4cdad8fc1be6f485ac08fccb32ba",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<=4,>=3.9",
            "size": 21898,
            "upload_time": "2024-07-14T18:21:53",
            "upload_time_iso_8601": "2024-07-14T18:21:53.854613Z",
            "url": "https://files.pythonhosted.org/packages/ff/80/5d666722c8a078fd41bc57825858791d950e38bdfafbd74a3f04e150e46d/plotdigitizer-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-14 18:21:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dilawar",
    "github_project": "PlotDigitizer",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "plotdigitizer"
}
        
Elapsed time: 1.29793s