8
$\begingroup$

I want to reflect a StreamPlot object across the x = 0 line. For example, let's say I have this code:

Bdcart[x_, y_, z_, m_] = 
  π/2 
    {(3 m x z)/(x^2 + y^2 + z^2)^(5/2), (3 m y z)/(x^2 + y^2 + z^2)^(5/2), 
     (m (3 z^2 - (x^2 + y^2 + z^2)))/(x^2 + y^2 + z^2)^(5/2)};
m = 1;
y = 0;
Bdsp = 
  StreamPlot[
    {Bdcart[x, y, z, m].{1, 0, 0}, 
     Bdcart[x, y, z, m].{0, 0, 1}}, 
    {x, 0, 2}, {z, -2, 2}, 
    StreamStyle -> Orange , PlotRange -> {{-2, 2}, {-2, 2}}]

This produces the following image:

enter image description here

I want to reflect it such that it will appear from -2 to 0.

Yes, I know that in this case I can just plot it from -2 to 0, but for my real case, it will not work. I also cannot plot StreamPlot[BDcart[-x,...],{x,0,-2}] in my real case. I really need to reflect the StreamPlot object and not do mathematical manipulations on it.

I've looked at this question, but I wasn't able to reproduce the behavior for a StreamPlot object.

$\endgroup$
  • 1
    $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – Michael E2 Nov 19 at 13:41
14
$\begingroup$
Bdsp /. Arrow[p_] :> {Arrow[p], Arrow[p.DiagonalMatrix[{-1, 1}]]}

enter image description here

$\endgroup$
  • $\begingroup$ This is elegant! $\endgroup$ – Chris K Nov 19 at 13:44
  • 1
    $\begingroup$ @Yomach, if you just want the reflected part, then drop the Arrow[p]: Bdsp /. Arrow[p_] :> {Arrow[p.DiagonalMatrix[{-1, 1}]]}. $\endgroup$ – Michael E2 Nov 19 at 13:46
  • $\begingroup$ This is perfect, thanks! Another question, How would I do it for a ContourPlot? $\endgroup$ – Yomach Nov 20 at 8:38
  • 1
    $\begingroup$ I'd do it slightly differently: cplot /. a_?(MatrixQ[#, Developer`MachineRealQ] &) :> a.DiagonalMatrix[{-1, 1}]. A similar approach to the above answer would be Normal[cplot] /. (h : Polygon | Line)[p_] :> h[p.DiagonalMatrix[{-1, 1}]] but the edges of the mesh show up with Normal[cplot] when I do it. To see the original and the reflection together, use something like Show[cplot, cplot /. a_?(MatrixQ[#, Developer`MachineRealQ] &) :> a.DiagonalMatrix[{-1, 1}], PlotRange -> All ] $\endgroup$ – Michael E2 Nov 20 at 13:11
  • 1
    $\begingroup$ The Normal[cplot] can be fixed with the trick from this answer: Normal[cplot] /. {EdgeForm[], r_?(MemberQ[{RGBColor, Hue, CMYKColor, GrayLevel}, Head[#]] &), i___} :> {EdgeForm[r], r, i} $\endgroup$ – Michael E2 Nov 20 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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