9
$\begingroup$

I'm trying to reproduce a few graphs in Mathematica after running my Fortran code. Ideally, I want exact quantitative agreement with the results already published in the literature. For example, I am trying to reproduce the four graphs on pp.50 of

http://ediss.sub.uni-hamburg.de/volltexte/2004/1133/pdf/dissertation.pdf

Is there any way I can copy/import snippets of these graphics and initialize these graphs in Mathematica so I can superimpose both the graphs and see if I have quantitative agreement. Or is that too far fetched an option?

$\endgroup$
  • $\begingroup$ If I understand your porblem I see one solution : first try to extract the graphics you want to import with the help of an external program --- like image extractor --- then you can use the command inset. Have a look at the question mathematica.stackexchange.com/questions/65669/… $\endgroup$ – cyrille.piatecki Sep 24 '16 at 8:44
  • 2
    $\begingroup$ There is one way based on the use of the function copyCurve published here: mathematica.stackexchange.com/questions/44355/…. It enables you to capture the points from the PDF plot as a list and to use them then in Mma. In your case of a highly oscillating functions it will require some work, to catch the curves in enough details. $\endgroup$ – Alexei Boulbitch Sep 24 '16 at 11:22
  • $\begingroup$ If possible, ask the author to provide you pictures for comparison. This is also honest way to conduct science: typically you need a permission for reproduction of published work. The copyright of dissertation belongs to the library of the corresponding university. $\endgroup$ – yarchik Sep 24 '16 at 11:27
  • $\begingroup$ @AlexeiBoulbitch This is a vector plot, all points are there. $\endgroup$ – yarchik Sep 24 '16 at 11:30
  • $\begingroup$ Related: "Is it possible to extract data from an EPS plot not generated in Mathematica?" $\endgroup$ – Alexey Popkov Nov 3 '16 at 7:35
19
$\begingroup$

The graphics we want are on page 50, but there are six prefatory pages labelled i through vi. So we will start by loading page 56 into memory:

$url = "http://ediss.sub.uni-hamburg.de/volltexte/2004/1133/pdf/dissertation.pdf";

$page50 = Import[$url, {"Pages", 56}] // First

PDF page graphic

We used First because importing PDF "Pages" returns of list of pages, in this case of one element.

The imported page is a Graphics expression:

$page50 // Head

(* Graphics *)

We can extract individual graphical elements from that expression. For example, here is the chapter title:

$page50[[1, 2]] // Graphics

chapter title graphic

It does not take much experimentation to locate our plots:

$page50[[1, 3;;30]] // Graphics

four plots as a graphic

... or to extract just the first curve:

$curve1 = $page50[[1, 3]];
$curve1 // Graphics

first curve as a graphic

The curve points can be extracted from this curve expression:

$curve1

(* Style[{JoinedCurve[{{{0, 2, 0}, {0, 1, 0}, ...}},
    {{{138.816, 709.0320000000002}, {139.023, 707.23},
      {139.20000000000002, 701.972}, ...}}, CurveClosed -> {0}]},
    JoinForm[{"Miter", 10.}], Thickness[0.0014893882352941176],
    RGBColor[0.47100000000000003, 0.47100000000000003, 1., 1.]]
*)

$curve1[[1, 1, 2, 1]]

(* {{138.816, 709.032}, {139.023, 707.23}, ..., {286.514, 655.299}} *)

$curve1[[1, 1, 2, 1]] // ListLinePlot

reconstituted curve 1

We need to rescale the points to the original axes:

$points1 //
  Transpose //
  Query[{1 -> (100 Rescale[#]&), 2 -> (2 Rescale[#] - 1 &)}] //
  Transpose //
  ListLinePlot

reconstituted curve 1 after rescaling

In the general case, rescaling can be more challenging. See (85329) for a more general treatment.

We have successfully recovered the original data points of the first curve and replotted them using Mathematica.

For completeness, here are the "addresses" of all of the individual curves:

$page50[[1, {3, 4, 10, 11, 17, 18, 24, 25}]] // Map[Graphics] // Column

individual curve graphics

$\endgroup$
  • 3
    $\begingroup$ I guess we're lucky in this case that the curves weren't rasterized. $\endgroup$ – J. M. will be back soon Oct 7 '16 at 5:59
  • 1
    $\begingroup$ Splendid answer. Although I could do my work by simply eye balling the graphs I made on Mathematica with those in the paper because they were a match. I'll use your methods for future purposes. $\endgroup$ – Junaid Aftab Oct 7 '16 at 6:16
  • $\begingroup$ (+1) Beautiful answer! But it is worth to note that the rescaling method used here is based on the assumption that the range of coordinates of the points is exactly equal to the plotting range what usually isn't the case. In the general case more involved approach based on reconstruction of the coordinate system from the axes' ticks is necessary, I show it in this answer. $\endgroup$ – Alexey Popkov Nov 3 '16 at 7:48
  • $\begingroup$ @AlexeyPopkov I added a reference to your answer to my response. Thanks. $\endgroup$ – WReach Nov 3 '16 at 14:00

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.