Group Abstract Group Abstract

Message Boards Message Boards

Can I Plot Multiple 2D Graph Slices as a Single Integrated 3D Graph?

GROUPS:
So, okay, here's my quandary, I'm working on a problem and have a solution for the even values I'm concerned with, but not yet for the odd values.

What I'd like to do is to graph some range of solutions as individual parts of a 3D graph. Essentially, they'd kind of be 2D cross sections of the incomplete 'continuous' 3D graph. If that makes sense. So, basically, I have a function that renders a periodic graph based upon the input of a positive even integer >= 4. So, I'd like to be able to use the function I have to output, say, the graphs where inputs are even integers 'Z' between 4 --> 20, and have it give me the resultant 2D graphs (0 <= X <= 2Pi), and then graph all of those 2D graphs in the same 3D space, where the 2D graph is on the X/Y plane, and each such graph is Z units deep in the 3D space.

Does that make sense?

Would I have to use an array or a table? ListPlot3D? How would I structure it?

Here's a version of my Sigma Function:

z = 6 (*z must be an even integer >= 4.*)
n = z/2
Plot[(Sum[Abs[Cos[((n + 2 + 2 (k - 1)) Pi)/(2 n)]], {k, 1, n}])/(Sum[Abs[Cos[x + (((n + 2 + 2 (k - 1)) Pi)/(2 n))]], {k, 1, n}]), {x, 0, 2 Pi}, PlotRange -> {0, 1}]

So, what I'm hoping for is that I can specify some range of values and then have Mathematica use the even values inside that range to run the function and then collate the 2D graphs it generates into a single 3D graph, with each slice at its correct z depth. If that makes sense?

Basically I want to plot the even valued graphs, so I can see what the overall plot looks like and makes some educated guesses about what the interstitial odd-valued graphs will look like.

Hope that kind of makes sense? So, is it possible to toss multiple 2D slices into a single 3D graph space? If so, what's the best way about it?

Best,
~MG
POSTED BY: Michael Gmirkin
Answer
2 months ago
I think there used to be a function for this way back in the olden days. Anyway, If you want lines wiggling through 3d space, you usually want ParametricPlot3D.

First I made a function that given an even number, computes the formula for that.
Then I made a list of 3D vector functions which represent the curve I'd want for each of lines. 
Then I gave the list of vector functions to ParametricPlot3D.

f[z_?EvenQ] := With[{n = z/2},  (Sum[Abs[Cos[((n + 2 + 2 (k - 1)) Pi)/(2 n)]], {k, 1, n}])/(Sum[     Abs[Cos[x + (((n + 2 + 2 (k - 1)) Pi)/(2 n))]], {k, 1, n}])]

funcs = Table[{x, z, f}, {z, 4, 10, 2}];

ParametricPlot3D[funcs, {x, 0, 2 Pi}]

You may want to play with the spacing a bit. Somtimes this is helpful, but it doesn't look very useful in this case at least. You'd use BoxRatio to change that:

ParametricPlot3D[funcs, {x, 0, 2 Pi}, BoxRatios -> {1, 0.3, 1}]
POSTED BY: Sean Clarke
Answer
2 months ago
Tried that in Mathematica and it came up with a blank cube?

But, not one to be deterred, I changed it to Table[{x, z, f}, ...] and that seemed to fix it?

Had to monkey with the settings a bit to get the proportions right-ish. Took me a while to figure out how to get the right info displayed on the various axes. & ended up relabeling the axes 'cause to me the vertical axis should by the Y axis, not the Z axis. But anyway...

GraphStart = 4  (* First graph to plot. Must be even integer. *)
GraphEnd = 60  (* Last graph to plot. Must be even integer. *)
f[z_?EvenQ] := With[{n = z/2}, (Sum[Abs[Cos[((n + 2 + 2 (k - 1)) Pi)/(2 n)]], {k, 1, n}])/(Sum[Abs[Cos[x + (((n + 2 + 2 (k - 1)) Pi)/(2 n))]], {k, 1, n}])]
funcs = Table[{x, z, f[z]}, {z, GraphStart, GraphEnd, 2}];
ParametricPlot3D[funcs, {x, 0, 2 Pi}, PlotRange -> {Automatic, {0, GraphEnd}, {0.5, 1}}, BoxRatios -> {1, 1, 1}, ViewPoint -> {8, -20, 10}, AxesEdge -> {{-1, -1}, {-1, -1}, {-1, -1}} , Ticks -> {Automatic, {2, 4, 6, 8, 10, 12, 14, 16, 18, 20},    Automatic}, PlotPoints -> 200, AxesLabel -> {"x axis", "z axis", "y axis"}]

One minor glitch is labeling the new 'Z' axis. I just want the even integer ticks labeled. But, so far, the only way I seem to be able to do that is to manually specify each and every one.

What I'd like to do is simply say something like Even Integers between 0 & 'GraphEnd.'

I tried inserting a Table into the Ticks parameter like "Ticks->{Automatic,Table[w,{w,0,GraphEnd,2}],Automatic}" but the graph highlighted red and no ticks were labeled. So, clearly that's not right.

Actually, it does seem to be right. For some reason the first time around it malfunctioned for some reason. Maybe I accidentally deleted a parenthesis or a curly brace or something. Regardless, it didn't like it. So, here's more-or-less what I'm working with now:

GraphStart = 4  (* First graph to plot. Must be even integer. *)
GraphEnd = 60  (* Last graph to plot. Must be even integer. *)
TicksTable := Table[t, {t, 0, GraphEnd, 2}];
f[z_?EvenQ] := With[{n = z/2}, (Sum[Abs[Cos[((n + 2 + 2 (k - 1)) Pi)/(2 n)]], {k, 1, n}])/(Sum[Abs[Cos[x + (((n + 2 + 2 (k - 1)) Pi)/(2 n))]], {k, 1, n}])]
funcs = Table[{x, z, f[z]}, {z, GraphStart, GraphEnd, 2}];
ParametricPlot3D[funcs, {x, 0, 2 Pi},
PlotRange -> {Automatic, {0, GraphEnd}, {0.5, 1}}, BoxRatios -> {1, 1, 1}, ViewPoint -> {8, -20, 10}, AxesEdge -> {{-1, -1}, {-1, -1}, {-1, -1}} , Ticks -> {Automatic, TicksTable, Automatic}, PlotPoints -> 200, AxesLabel -> {"x axis", "z axis", "y axis"}]

Seems to more-or-less do what I was hoping it would do...

Though I guess I'm still not sure why it needs to be a ParametricPlot3D as opposed to a ListPlot3D. Or is there a way to accomplish the same thing with ListPlot3D? Dunno...

I guess, as long as it does what I need for visualization, the nuts and bolts can remain something of a mystery. emoticon

Thanks,
~MG
POSTED BY: Updating Name
Answer
2 months ago
Is there a way to do something similar with ListPlot3D that will use those slices, and then try to graph a 3D graph based upon them (interpolating intermediate values)?

I tried something similar but it didn't come up with anything remotely like the graph I was looking for, so I probably did it totally wrong...

~MG
POSTED BY: Michael Gmirkin
Answer
2 months ago
This doesn't fiddle with the tick labels but I think otherwise does what you request.

Edit. Simple revision which I should have thought of initially and which fixes the tick labels.
ListPlot3D[Flatten[Table[n = z/2; {x, z,(Sum[Abs[Cos[((n + 2 + 2 (k - 1)) Pi)/(2 n)]], {k, 1, n}])/(Sum[
  Abs[Cos[x + (((n + 2 + 2 (k - 1)) Pi)/(2 n))]], {k, 1, n}])}, {x, 0, 2 Pi, Pi/128}, {z, 4, 20, 2}], 1]]
POSTED BY: Bill Simpson
Answer
2 months ago
Also, I made this other graph on my own using the first one as a sort of template (even if I don't completely understand the precise function; black boxes & all that):

 xStart = 0
 xEnd = 2 Pi
 zStart = 3 (* First graph to plot. Must be even integer. *)
 zEnd = 50  (* Last graph to plot. Must be even integer. *)
 xTicksTable := Table[xt, {xt, 0, xEnd, Pi/8}];
 zTicksTable := Table[zt, {zt, 0, zEnd, 2}];
 increment = 1/2
 f[z_] := Cos[Pi/z]/Cos[Mod[x, 2 Pi/z] - Pi/z];
 func = Table[{x, z, f[z]}, {z, zStart, zEnd, increment}];
ParametricPlot3D[func, {x, xStart, xEnd}, PlotRange -> {Automatic, {0, zEnd}, {0.5, 1}}, BoxRatios -> {1, 1, 1}, ViewPoint -> {8, -20, 10}, AxesEdge -> {{-1, -1}, {-1, -1}, {-1, -1}} , Ticks -> {xTicksTable, zTicksTable, Automatic}, PlotPoints -> 100, AxesLabel -> {"x axis", "z axis", "y axis"} ]

It utilizes a different form of the same graph (one I don't like for my final solution due to the Mod[] function, which I find undesirable, but which renders the same results as those I'm looking for). Basically for visualization purposes, so I can try to figure out what the graph is supposed to do and see if there's a way to do it in my preferred function(s) format.

Clearly, a pattern emerges as one increases zEnd, and/or reduces increment.

Though I'm still not sure how to generalize for all values z >=3 (only know the form for even values of z>=4), at least I know there's potentially an interesting pattern to be found/generalized. emoticon

Best,
~MG
POSTED BY: Michael Gmirkin
Answer
1 month ago
And, with thanks to Bill for the additional 'template,' I've also constructed the following alternate version of the ListPlot3D based on the Mod[] function:

 xStart = 0
 xEnd = 2 Pi
 yStart = 0.5
 yEnd = 1
 zStart = 3 (* First graph to plot. Must be >=3. *)
 zEnd = 40  (* Last graph to plot. *)
 increment = 1/8
 xTicksTable := Table[xt, {xt, 0, xEnd, Pi/8}];
 yTicksTable := Table[yt, {yt, yStart, yEnd, 1/10}];
zTicksTable := Table[zt, {zt, 0, zEnd, 2}];
ListPlot3D[Flatten[Table[{x, z, (Cos[Pi/z]/Cos[Mod[x, 2 Pi/z] - Pi/z])}, {x, xStart, xEnd, Pi/128}, {z, zStart, zEnd, increment}], 1], PlotRange -> {Automatic, {0, zEnd}, {yStart, yEnd}}, BoxRatios -> {1, 1, 1}, ViewPoint -> {8, -20, 10}, AxesEdge -> {{-1, -1}, {-1, -1}, {-1, -1}}, Ticks -> {xTicksTable, zTicksTable, yTicksTable}, AxesLabel -> {"x axis", "z axis", "y axis"}]

Which does a pretty passable job roughing out the 3D shape of whatever the final graph should be, if I ever get it all figured out in my preferred function format... ^_^

Rather interesting to play with.
~MG
POSTED BY: Michael Gmirkin
Answer
1 month ago
And, since I could, I also created thsi Plot3D graph of the Mod[] function based graph. Though, strangely, it seems to cut off the tops/ridges of the graph and leave holes you can see down, which is kinda' weird. Not sure why... Did I do something wrong, or is Mathematica just being finnicky?

 xStart = 0
 xEnd = 2 Pi
 yStart = 0.5
 yEnd = 1
 zStart = 3 (* First graph to plot. Must be even integer. *)
 zEnd = 40  (* Last graph to plot. Must be even integer. *)
 xTicksTable := Table[xt, {xt, 0, xEnd, Pi/8}];
 yTicksTable := Table[yt, {yt, yStart, yEnd, 1/10}];
 zTicksTable := Table[zt, {zt, 0, zEnd, 2}];
Plot3D[(Cos[Pi/y]/Cos[Mod[x, 2 Pi/y] - Pi/y]), {x, xStart, xEnd}, {y,   zStart, zEnd}, PlotRange -> {{xStart, xEnd}, {0, zEnd}, {yStart, yEnd}}, PlotPoints -> 200, BoxRatios -> {1, 1, 1}, ViewPoint -> {8, -20, 10},  AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}}, Ticks -> {xTicksTable, zTicksTable, yTicksTable}, AxesLabel -> {"x axis", "z axis", "y axis"}]

Anyway, some interesting visualizations... To me anyway. ^_^

~MG
POSTED BY: Michael Gmirkin
Answer
1 month ago