1
$\begingroup$

I have the following code

Posvec = {Cos[\[Phi]] Sin[\[Theta]], Sin[\[Theta]] Sin[\[Phi]], 
Cos[\[Theta]]};
Func = Function[{z}, -z^2];
P1 = ParametricPlot[{ Func[Posvec[[3]]], Posvec[[3]]}, {\[Theta], 
0, \[Pi]}, PlotRange -> All, AspectRatio -> Full, 
ColorFunction -> Function[{x, y}, Hue[-x]], 
ColorFunctionScaling -> False];
L1 = ParametricPlot3D[
Posvec, {\[Phi], 0, 2 \[Pi]}, {\[Theta], 0.01, 0.9999 \[Pi]},  
Axes -> False, Boxed -> False, 
ViewVector -> {{100, 0, 0}, {0, 0, 0}}, PlotPoints -> {50, 50}, 
ColorFunction -> Function[{x, y, z, \[Phi], \[Theta]}, Hue[z^2]], 
ColorFunctionScaling -> False];
GraphicsGrid[{{P1, L1}}, Alignment -> Center]

This first creates 2 plots like this

enter image description here

and this

enter image description here

The last line then creates an image of both plots next to each other. Like this

enter image description here

Now, technically the color plot on the ball and the parabola represent the same value. I would like them to either share the z-axis or at least have the ball and the plot the same height. I really tried, but don't seems to be very successful! As a second thing it would be really nice if one could bring them closer together.

I would be really happy about help

Thanks in advance!

$\endgroup$

1 Answer 1

4
$\begingroup$

Perhaps the simplest way is to also plot the curve in 3D.

posvec = {Cos[ϕ] Sin[θ], Sin[θ] Sin[ϕ], Cos[θ]};
movevec = {1.5, 0, 0};
func = Function[{z}, -z^2];

curve = ParametricPlot3D[{func[posvec[[3]]], 0, 
    posvec[[3]]}, {θ, 0, π}, PlotRange -> All, 
   AspectRatio -> Full, ColorFunction -> Function[{x, y}, Hue[-x]], 
   ColorFunctionScaling -> False];
sphere = ParametricPlot3D[
   posvec + movevec, {ϕ, 0, 2 π}, {θ, 0, π}, 
   Axes -> False, Boxed -> False, PlotPoints -> {50, 50}, 
   ColorFunction -> Function[{x, y, z, ϕ, θ}, Hue[z^2]], 
   ColorFunctionScaling -> False];

Show[{curve, sphere}, ViewPoint -> Front, 
 ViewProjection -> "Orthographic", 
 PlotRange -> {{-1, 3}, {-2, 4}, Automatic}, AxesOrigin -> {0, 0, 0}, 
 AspectRatio -> 1/2]

Method 1

Alternatively, you can manually set all the relevant options (PlotRange, ImageMargins, ImagePadding, SphericalRegion), and combine with Row or GraphicsRow.

curve = ParametricPlot[{func[posvec[[3]]], posvec[[3]]}, {\[Theta], 
    0, \[Pi]}, ColorFunction -> Function[{x, y}, Hue[-x]], 
   ColorFunctionScaling -> False, PlotRange -> {{-1, 0}, {-1, 1}}, 
   ImageSize -> {150, 200}, ImageMargins -> 0, ImagePadding -> 20, 
   AspectRatio -> Full];

sphere = ParametricPlot3D[
   posvec, {\[Phi], 0, 2 \[Pi]}, {\[Theta], 0, \[Pi]}, Axes -> False, 
   Boxed -> False, PlotPoints -> {50, 50}, 
   ColorFunction -> Function[{x, y, z, \[Phi], \[Theta]}, Hue[z^2]], 
   ColorFunctionScaling -> False, ViewPoint -> Front, 
   ViewProjection -> "Orthographic", 
   PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}, AxesOrigin -> {0, 0, 0}, 
   ImageSize -> {200, 200}, SphericalRegion -> False, 
   ImageMargins -> 0, ImagePadding -> 20];

Row[{curve, sphere}]

Method 2

$\endgroup$
4
  • $\begingroup$ Genius!!!!!!!!! $\endgroup$
    – jabru
    Dec 28, 2022 at 21:40
  • $\begingroup$ But what if the $x$-axes need to scale differently? $\endgroup$
    – jabru
    Dec 28, 2022 at 23:05
  • $\begingroup$ Well, in that case, you can manually transform (scale) the object by multiplying the $x$ coordinate. $\endgroup$
    – Domen
    Dec 28, 2022 at 23:06
  • $\begingroup$ @jabru, I have also added a second method, which is perhaps more suitable to your needs. $\endgroup$
    – Domen
    Dec 28, 2022 at 23:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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