1

In the old days, if someone had a scientific graph, then readers would only have access to the rastered image. So if you wanted to get the raw data from the plot, you could use something like DataThief or Webplotdigitizer on a rastered image like the one below.

Raster image example

These days, scientific publications usually require authors to submit plots in vector format (pdf or eps). Which means you can directly open up the plot in illustrator and see the data being plotted (usually as some path object?). For example, Figure 5a from here is a vector plot that is accessible from the pdf (reproduced below).

From the referenced pdf Figure 5a

My questions are the following:

  1. What are the usual object types for a line in an XY plot (see Figure 5a in the above pdf)?
  2. What is the best way to run a script over the object (in Illustrator or some other program) to get the exact position of the points of the line?

Edit: I already saw this question, but rather than just getting a single point associated with the object, I wanted to absolute position of all the sub-points (if that makes sense). That way I can recreate the graph using the positions of the axes labels.

3

The usual object type for a graph in vector graphic is a path (called pathItem in the Illustrator JavaScript API). It could be one joined ragged line, a smooth bezier curve and sometimes separate straight lines. Depends on the program generating the graph.

I have written a little script to get you started extracting the points from a graph:

#target illustrator

// the current selection
var selection = app.activeDocument.selection;

// create a txt-file for the data
var file = File.saveDialog('Save a comma-separated list of the x and y coordinates of the points of the current selection, relative to the coordinate system of the artboard.', 'Comma-separated values:*.csv');

// enable writing to the file
file.open('w')

// iterate through each selected item
for (var i = 0; i < selection.length; i++) {
  var item = selection[i];

  // check if selection is a PathItem
  if (item.typename === "PathItem") {

    // every PathItem has a list of pathPoints
    var points = item.pathPoints;

    // iterate through each pathPoint of the item
    for (var j = 0; j < points.length; j++) {

      // the point in document coordinates, relative to the center of the whole document
      var documentPoint = points[j].anchor;

      // the point converted to artboard coordinates, relative to where you have placed the origin of the coordinate system
      var artboardPoint = app.activeDocument.convertCoordinate(documentPoint, app.coordinateSystem, CoordinateSystem.ARTBOARDCOORDINATESYSTEM);

      // write the artboard coordinates to the file
      file.write(artboardPoint[0] + "," + artboardPoint[1] + "\n");
    }
  }
}

// stop writing to the file and save it
file.close();

The script creates a .csv file containing a comma-separated list of the x and y coordinates of the points of the current selection, relative to the coordinate system of the artboard.

I would recommend first moving the origin of the artboard ruler to the origin of the graph, then select only the graph itself and run the script.

If your graph is made of separate lines, you will get a lot of duplicate points. You could remove them in the .csv file or you could "clean up" your graph first using my script from this answer or integrate the two scripts.

  • This looks like precisely what I want, going to try it out as soon as I get home – user157879 Nov 6 '17 at 22:57
  • Additional question, what happens when the curve is more then segmented lines and has something like bezier curves within it? – user157879 Nov 7 '17 at 0:37
  • The script ignores the curve and only returns the coordinate of the anchor point. – Wolff Nov 7 '17 at 1:04
  • I see, is there a clean way to tell if the path between two anchors is a straight line, bezier curve, etc.? – user157879 Nov 7 '17 at 2:19
  • The two control points of a pathPoint is stored in the properties "rightDirection" and "leftDirection". If they are different from the "anchor" it's a curve, if they are the same it's a straight line. You could check out the documentation for more info. – Wolff Nov 8 '17 at 0:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.