Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

I did some calculations and as result got a 2D graphic, but at the beginning of the work I used a constant parameter. What I want is to make a 3D graphic with this parameter as an axis, varying from 1 to 100. How to proceed?

share|improve this question

marked as duplicate by J. M. Jul 26 at 11:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Hi ! You have to provide a minimum working example that illustrates the whole problem, so we can start working. – Sektor Aug 15 '14 at 0:41
Can you give some more details on how you generated the 2D graphics? – Rahul Aug 15 '14 at 0:41

1 Answer 1

Generally speaking Mathematica has 3D versions of everything, so you are probably best to use those from the start. But if you really want to convert 2D to 3D, then you could do it with a set of rules:

linerule[z_] := Line[points_, stuff___] :> Line[{First@#, Last@#, z} & /@ points, stuff];
textrule[z_] := Text[t_, {x_, y_}, stuff___] :> Text[t, {x, y, z}, stuff];
(* pointRule, graphicsComplexRule, polygonRule, etc. *)
allrules[z_] := {linerule[z], textrule[z]};

It's not so simple as taking a list of two numbers to a list of three. Sometimes your list of two numbers might not be a 2D point. So these rules specifically target the bits which we know are coordinates. Some primitives like Circle are going to be more that just appending a z coordinate.

As an example use:

p[z_] := Plot[(x - z)^2, {x, 0, 1}, PlotRange -> {{0, 1}, {0, 1}}, PlotStyle -> Thick];

  Table[First@FullGraphics@p[z] /. allrules[z], {z, 0, 1, 0.2}]
, Boxed -> False]


share|improve this answer
In routine maintenance I was preparing to delete this old closed question, but your answer seems interesting. Since the question is otherwise abandoned would you consider editing it to specifically fit this answer, or reposting this in a self-Q&A? – Mr.Wizard Jul 25 at 13:46

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