Wolfram: Extract Graphics from Builtin Plot Functions

By Xah Lee. Date: . Last updated: .

Extract Graphics from Builtin Plot Functions

all builtin functions that display graphics return either a Graphics or Graphics3D expression.

the first element of it is a list of Graphics Primitives (and directives). (or, a GraphicsComplex that represent list of graphics primitives. )

so, to exctract graphics primitives, just get the first element of the result.

Example: 2D Graphics

(* extract the graphic primitives from a builtin plot function *)
gr = Plot[ Sin[x], {x,0,5} ];

(* length is always 2 *)
Length[gr]
(* 2 *)

(* head always Graphics or Graphics3D *)
Head[gr]
(* Graphics *)

(* get list of graphics primitives and directives. *)
gp = First[gr]
wl extract graphics 2024-06-05
wl extract graphics 2024-06-05

Example: 3D Graphics

gr = Plot3D[ Sin[x] Cos[y], {x,0,5}, {y,0,5} ];

Length[gr]
(* 2 *)

Head[gr]
(* Graphics3D *)

(* get list of graphics primitives and directives. *)
gp = First[gr]
wl 2024-06-05 133215
wl 2024-06-05 133215

WolframLang, Graphics Programing