3
$\begingroup$

I got this from examples, and it works, but I can not understand it

first the initial data

f1[x_] := 4 x^3 + 0.1 x^2 - 7 x - 1
pss = Plot[f1[x], {x, -1.3, 1.53}]

then

mx = Max[Last /@ Level[Cases[pss, _Line, Infinity], {-2}]]

or

mn = Min[Last /@ Level[Cases[pss, _Line, Infinity], {-2}]]

both work but I do not understand this _Line ??

$\endgroup$

1 Answer 1

6
$\begingroup$

This goes back to the basic structure of expressions in WL. Every expression has a Head, even the built-in operators, like List:

FullForm[{1,2,3}]
(*List[1,2,3]*)

For a pattern,

_h

this will match expressions with Head h. So, in

Cases[pss, _Line, Infinity]

_Line matches Line[...]. Note: it won't match the bare symbol, e.g.

MatchQ[Line, _Line]
(* False *)

because

Head[Line]
(* Symbol *)
$\endgroup$
3
  • $\begingroup$ Now I saw, after doing FullForm that the only part of huge basic commands is the one preceded by Line, before I did not undertand how complex a simple Plot can be. Thanks for help @rcollyer $\endgroup$ Commented Aug 15, 2018 at 19:29
  • 1
    $\begingroup$ @AnxonPués I don't recommend viewing Plot using FullForm it's liable to drive you mad. :) InputForm is bad enough. A difficulty is that the FullForm is how an expression is interpreted, but due to wanting "nice" markup, the details are often hidden. Try a/b, for instance. :) $\endgroup$
    – rcollyer
    Commented Aug 15, 2018 at 20:03
  • 1
    $\begingroup$ @AnxonPués You may want to try shortInputForm. $\endgroup$
    – xzczd
    Commented Aug 16, 2018 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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