4
$\begingroup$

Sometimes I want to investigate the structure of Graphics/Graphics3D which is produced by Plot/Plot3D or similar command. Often InputForm produces a very big output

Plot[x, {x, 0, 1}] // InputForm
(* Graphics[{{{}, {}, {Directive[Opacity[1.], RGBColor[0.368417, 0.506779, 
      0.709798], AbsoluteThickness[1.6]], Line[{{2.040816326530612*^-8, 
     2.040816326530612*^-8}, {0.000306717908041361, 0.000306717908041361},
     ... points, points, points ...
     {0.9999999795918367, 0.9999999795918367}}]}}}, 
 {DisplayFunction -> Identity, AspectRatio -> GoldenRatio^(-1), 
  Axes -> {True, True}, AxesLabel -> {None, None}, AxesOrigin -> {0, 0}, 
  DisplayFunction :> Identity, Frame -> {{False, False}, {False, False}}, 
  FrameLabel -> {{None, None}, {None, None}}, 
  FrameTicks -> {{Automatic, Automatic}, {Automatic, Automatic}}, 
  GridLines -> {None, None}, GridLinesStyle -> 
   Directive[GrayLevel[0.5, 0.4]], 
  Method -> {"DefaultBoundaryStyle" -> Automatic, 
    "ScalingFunctions" -> None}, PlotRange -> 
   {{0, 1}, {0., 0.9999999795918367}}, PlotRangeClipping -> True, 
  PlotRangePadding -> {{Scaled[0.02], Scaled[0.02]}, 
    {Scaled[0.05], Scaled[0.05]}}, Ticks -> {Automatic, Automatic}}] *)

What is the simplest way to get a small and informative output?

For example, in version 9 and earlier I can use // InputForm // Developer`PackedArrayForm

Plot[x, {x, 0, 1}] // InputForm // Developer`PackedArrayForm

(* Graphics[{{{}, {}, {Hue[0.67, 0.6, 0.6], 
 Line["PackedArray"[Real, "<"77","2">"]]}}}, 
 {AspectRatio -> GoldenRatio^(-1), Axes -> True, AxesLabel -> {None, None},
 AxesOrigin -> {0, 0}, Method -> {}, PlotRange -> {{0, 1}, {0., 0.9999999795918367}}, 
 PlotRangeClipping -> True, PlotRangePadding -> {Scaled[0.02], Scaled[0.02]}}] *)

I see all options and I see the dimensions of a big data arrays. It is not the case for Short or Shallow

Plot[x, {x, 0, 1}] // InputForm // Short
(* Graphics[{{{}, {}, {Directive[<<3>>], Line[{<<77>>}]}}}, {<<16>>}] *)

However, in V10 Developer`PackedArrayForm produces a mess with InputForm

Plot[x, {x, 0, 1}] // InputForm // Developer`PackedArrayForm
(* Graphics[{{{}, {}, {Directive[Opacity[1.], RGBColor[0.368417, 0.506779, 0.709798], 
 AbsoluteThickness[1.6]], Line["PackedArray"[Real, Row[{Style["<",
    ShowStringCharacters -> False, StripOnInput -> True], Row[{77, 
    Style[",", ShowStringCharacters -> False], 2}, StripOnInput -> True],
    Style[">", ShowStringCharacters -> False, StripOnInput -> True]},
    StripOnInput -> True]]]}}}, 
{DisplayFunction -> Identity, AspectRatio -> GoldenRatio^(-1), Axes -> {True, True}, 
AxesLabel -> {None, None}, AxesOrigin -> {0, 0}, DisplayFunction :> Identity, 
Frame -> {{False, False}, {False, False}}, FrameLabel -> {{None, None}, {None, None}}, 
FrameTicks -> {{Automatic, Automatic}, {Automatic, Automatic}}, 
GridLines -> {None, None}, GridLinesStyle -> Directive[GrayLevel[0.5, 0.4]], 
Method -> {"DefaultBoundaryStyle" -> Automatic, "ScalingFunctions" -> None}, 
PlotRange -> {{0, 1}, {0., 0.9999999795918367}}, PlotRangeClipping -> True, 
PlotRangePadding -> {{Scaled[0.02], Scaled[0.02]}, {Scaled[0.05], Scaled[0.05]}}, 
Ticks -> {Automatic, Automatic}}] *)

Could you propose an alternative approach? May be I miss something very simple. I don't want to write a complicated parser. The main goal is to do it as fast and simple as possible.

$\endgroup$
7
  • $\begingroup$ related $\endgroup$
    – Kuba
    Sep 18 '14 at 17:08
  • $\begingroup$ How about Plot[x, {x, 0, 1}] // InputForm // Short? Or, if you need more control, Short[InputForm[Plot[x, {x, 0, 1}]], 10]. $\endgroup$ Sep 18 '14 at 17:10
  • $\begingroup$ @MarkMcClure As I show in the post, it hides the options. Options are more significant for the graphics then the particular values of the data. It is not convenient to find every time a threshold for Short which will show the options and do not show a lot of points. $\endgroup$
    – ybeltukov
    Sep 18 '14 at 17:18
  • $\begingroup$ Sorry, I posted a comment since I looked at your post quite quickly. Does Plot[x, {x, 0, 1}] // Options help? $\endgroup$ Sep 18 '14 at 17:24
  • $\begingroup$ @MarkMcClure Sometimes it can help. However, suddenly I find a simple solution, which I posted as the answer. $\endgroup$
    – ybeltukov
    Sep 18 '14 at 17:44
7
$\begingroup$

I find a simple version-independent solution, which produces a very clear output

List @@ Plot[x, {x, 0, 1}] // Developer`PackedArrayForm

enter image description here

Moreover, it allows a brackets-matching and a multiple-click highlighting!

$\endgroup$
5
$\begingroup$
show = {Short@First@#, Last@#} &;

Plot[x, {x, 0, 1}] // show

enter image description here

$\endgroup$
1
  • $\begingroup$ Nice! I added the snapshot. I hope you don't mind. $\endgroup$
    – ybeltukov
    Sep 18 '14 at 17:59

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.