Extract raw data from plots images
Project description
A Python3 utility to digitize plots.
Installation
$ python3 -m pip install plotdigitizer
$ plotdigitizer --help
Usage
First, remove all text from the image, leave only axis and the plot. I use
gthumb
utility. 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.
Run the utility
plotdigitizer ./figures/trimmed.png -p 0,0 -p 10,0 -p 0,1
We need three points (-p
option) to map axes onto the images. In the example
above, these are 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 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.
The data-points will be dumped to a csv file e.g., --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
.
Notice the errors near the boxes; since we have not trimmed them.
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.
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 for these 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 _assuming that bottom left
of the image is first row, first column (0,0)
. We have provide a utility
plotdigitizer-locate
(script plotdigitizer/locate.py
) which you can use on
the image to find the coordinates.
If you have installed the utility using pip install
$ plotdigitizer-locate figures/trimmed.png
or, from the source,
$ python3 plotdigitizer/locate.py figures/trimmed.png
This open a windows, you can click on the desired point and its coordinate will be written on the image itself. Note them down.
Examples
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
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
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.
Related projects by others
- WebPlotDigitizer by Ankit Rohatagi is very versatile.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for plotdigitizer-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49748c3d60a2a23d254467c22f9e8845adec173a2f9cfc873a06350468b94720 |
|
MD5 | 21d1fbab7fe08f95e84e12b404bfbcaa |
|
BLAKE2b-256 | 89bbff753093458c05ce3b52fd17527b6b0622ca096aadcf561c6316320ab793 |