Mathematica , Combining 2D and 3D plots

In summary: Thanks ... for both :-) ... I really need this and I couldn't find a way to show 2d and 3d graph, and when I finally made something up the 2d graph was right in the middle of the 3d plot and had it's own axis ... anyway thank you very much it helped me very much :)
  • #1
PeetPb
29
0
Hi,

I was thinking if there is a way to combine 2D and 3D plots in mathematica. I mean, for example I have a curve on the XY plane and I want to combine it with a graph of a surface, so to have that curve under the surface. The other case , to combine a 2D vector field with a surface .. something like http://en.wikipedia.org/wiki/File:Gradient99.png"
Any Ideas ?

thanks
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
Hi PeetPb, welcome to PF!

The key is that you cannot Show 2D and 3D graphics together. So you have to use the 2D graphic as a Texture for a 3D polygon. Then you Show those two objects together.

Show[Plot3D[Sin[x], {x, -\[Pi], \[Pi]}, {y, -1, 1}],
Graphics3D[{Texture[Plot[Cos[x], {x, -\[Pi], \[Pi]}]],
Polygon[{{-\[Pi], -1, 0}, {\[Pi], -1, 0}, {\[Pi], 1, 0}, {-\[Pi],
1, 0}}, VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0,
1}}]}, Lighting -> "Neutral"]]
 
  • #3
DaleSpam said:
Hi PeetPb, welcome to PF!

The key is that you cannot Show 2D and 3D graphics together. So you have to use the 2D graphic as a Texture for a 3D polygon. Then you Show those two objects together.

Show[Plot3D[Sin[x], {x, -\[Pi], \[Pi]}, {y, -1, 1}],
Graphics3D[{Texture[Plot[Cos[x], {x, -\[Pi], \[Pi]}]],
Polygon[{{-\[Pi], -1, 0}, {\[Pi], -1, 0}, {\[Pi], 1, 0}, {-\[Pi],
1, 0}}, VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0,
1}}]}, Lighting -> "Neutral"]]

Thanks ... for both :-) ... I really need this and I couldn't find a way to show 2d and 3d graph, and when I finally made something up the 2d graph was right in the middle of the 3d plot and had it's own axis ... anyway thank you very much it helped me very much :)

I actually found out a way how to "combine" a parametric curve and a surface

ParametricPlot3D[{{x, y, Cos[2 x + y]}, {x, x^2, -1}}, {x, 0, 2}, {y,
0, 2}, BoxRatios -> {1, 1, 1}]
 

1. How do I combine 2D and 3D plots in Mathematica?

To combine 2D and 3D plots in Mathematica, you can use the Show command. First, plot your 2D and 3D functions separately using the Plot and Plot3D functions. Then, use Show to combine them into one plot. For example, Show[Plot[x^2, {x, 0, 5}], Plot3D[x^2 + y^2, {x, 0, 5}, {y, 0, 5}]] will combine the 2D parabola and 3D paraboloid into one plot.

2. Can I customize the appearance of the combined plot?

Yes, you can customize the appearance of the combined plot using various options in the Show command. For example, you can use the PlotStyle option to change the color and style of the lines in the 2D plot, and the MeshStyle option to change the color and style of the mesh lines in the 3D plot.

3. Is it possible to add a legend to the combined plot?

Yes, you can add a legend to the combined plot using the PlotLegends option in the Show command. You can specify the labels for each plot and their corresponding styles. For example, Show[Plot[x^2, {x, 0, 5}, PlotStyle -> Red], Plot3D[x^2 + y^2, {x, 0, 5}, {y, 0, 5}, MeshStyle -> Green, PlotLegends -> {"2D Plot", "3D Plot"}] will add a legend with the labels "2D Plot" and "3D Plot" and their corresponding colors.

4. How can I add labels and titles to the combined plot?

You can add labels and titles to the combined plot using the PlotLabel and AxesLabel options in the Show command. For example, Show[Plot[x^2, {x, 0, 5}, PlotLabel -> "Parabola", AxesLabel -> {"x", "y"}], Plot3D[x^2 + y^2, {x, 0, 5}, {y, 0, 5}, PlotLabel -> "Paraboloid", AxesLabel -> {"x", "y", "z"}]] will add a title and axes labels for both the 2D and 3D plots.

5. Can I combine multiple 2D and 3D plots into one plot?

Yes, you can combine multiple 2D and 3D plots into one plot using the Show command. Simply include all the plots you want to combine within the Show command. For example, Show[Plot[x^2, {x, 0, 5}], Plot3D[x^2 + y^2, {x, 0, 5}, {y, 0, 5}], Plot[Sin[x], {x, 0, 5}]] will combine a 2D parabola, 3D paraboloid, and sine curve into one plot.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
144
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top