3

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 ??

Anxon Pués
  • 907
  • 5
  • 13

1 Answers1

6

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 *)
rcollyer
  • 33,976
  • 7
  • 92
  • 191
  • 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 – Anxon Pués Aug 15 '18 at 19:29
  • 1
    @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. :) – rcollyer Aug 15 '18 at 20:03
  • 1
    @AnxonPués You may want to try shortInputForm. – xzczd Aug 16 '18 at 07:59