Wolfram: Extract Graphics from Plot Functions

By Xah Lee. Date: . Last updated: .

Extract Graphics from Builtin Plot Functions

Builtin plot functions return Graphics or Graphics3D expression. 〔see Wolfram: Graphics, Graphics3D

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

The rest elements are options, such as as specifying axes, aspect ratio, etc.

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 the graphics primitives. *)
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 the graphics primitives. *)
gp = First[gr]
wl 2024-06-05 133215
wl 2024-06-05 133215

Get Axes, Frame, Etc as Graphics Primitives

Wolfram. Graphics Programing