4
$\begingroup$

I have been using the points of Mathematica plots for more than 25 years and it suddenly does not work any longer in version 11:

gr = Plot[Sin[2 \[Pi] x], {x, 0, 1}]

result of the plot

gr[[0]]

returns Graphics

gr[[1, 1, 1, 3]]

returns

{Directive[Opacity[1.], RGBColor[0.368417, 0.506779, 0.709798], AbsoluteThickness[1.6]], 
Line[{{2.04082*10^-8, 1.28228*10^-7}, {0.000306718, 
0.00192716}, {0.000613415, 0.00385419}, {0.00122681, 
0.0077082}, {0.0024536, 0.0154158}, {0.00490718, 
0.0308278}, {0.00981434, 0.0616262}, {0.0196287, 0.123018},....

The points seem to be there and reachable, but

gr[[1, 1, 1, 3, 2]

returns "ChartingPrivateTag$109972#1" instead of the Line[] with the points!

How to get the points in version 11 (and above)?

Thank you for your help.

Denis

$\endgroup$
  • $\begingroup$ Moving my answer to comment, probably more appropriate: it actually works for me (v11.3 on mac osx), I don't get the error: have you tried restarting the kernel? maybe you have some definitions that are creating some conflict.. but it sounds very weird $\endgroup$ – Fraccalo Feb 26 at 11:58
  • 1
    $\begingroup$ Try gr[[1, 1, 1, 3, 1, 2]]. The actual list which contains the line primitive is wrapped by an Annotation that can only be seen with FullForm or InputForm. But indeed weird; these Annotation wrappers haven't been there in former versions. $\endgroup$ – Henrik Schumacher Feb 26 at 12:11
  • $\begingroup$ Thank you Fraccalo. My version is 11.1 and I have the problem with a fresh Kernal and only the code above... $\endgroup$ – user3650925 Feb 26 at 12:13
  • $\begingroup$ Thank you Enrik. gr[[1, 1, 1, 3, 1, 2]] works !!! But Why? $\endgroup$ – user3650925 Feb 26 at 12:16
  • 1
    $\begingroup$ @user3650925 As I said: The actual Line primitive lies a level deeper because of an (almost) invisible wrapper called Annotation. Have a look at InputForm[gr[[1, 1, 1, 3]]] to see it. $\endgroup$ – Henrik Schumacher Feb 26 at 12:49
5
$\begingroup$
Cases[gr, Line[x_] :> x, -1]
$\endgroup$
  • $\begingroup$ This is probably the most robust (and future-proof) approach possible. $\endgroup$ – Henrik Schumacher Feb 26 at 13:03
  • $\begingroup$ ah yes, it is an interesting alternative that will work in any version. Thank you. $\endgroup$ – user3650925 Feb 26 at 13:10
  • 1
    $\begingroup$ @HenrikSchumacher Thanks for your comment, I hope so. $\endgroup$ – Αλέξανδρος Ζεγγ Feb 26 at 13:12
  • $\begingroup$ @user: it's not an "alternative"; it's a standard way to extract graphics primitives from a plotting function, which as noted doesn't need to know how deeply the primitves are buried in Graphics[]. $\endgroup$ – J. M. is away Feb 27 at 0:44

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.