I tried to put a zigzag line within a plot that here is a Streamplot.

However, I failed to combine the figures using Show command.

Would you be so kind as to let me know what is the problem?

I want to put the zigzag line from (x=0,y=0) to (x=0,y=10) within the figure.

s1 := StreamPlot[{1/(x + 1), 1/(y + 1)}, {x, 0, 1}, {y, 0, 1}]
s2 := Rotate[Graphics[Line[Table[{n, (-1)^n}, {n, 120}]]], 90 Degree]
Show[{s1, s2}]
  • $\begingroup$ Only two Graphics can be combined. s2 has head Rotate, not Graphics. Apply Rotate only to the contents of Graphics, not Graphics itself. $\endgroup$ – Szabolcs Apr 24 at 16:55
  • 1
    $\begingroup$ Since you signed your post anyway, please consider setting a username. "user14750" is very hard to distinguish from any other "userXXXXX". $\endgroup$ – Szabolcs Apr 24 at 16:56
  • $\begingroup$ related: search results - Rotate + Show $\endgroup$ – kglr Apr 25 at 6:02

Try giving the Epilog option to your stream plot.

StreamPlot[{1/(x + 1), 1/(y + 1)}, {x, 0, 1}, {y, 0, 1},
  Epilog -> Rotate[Line[Table[{n, (-1)^n}, {n, 120}]/120], 90 °, {0, 0}]]



  1. you must use the 3rd argument of Rotate to specify you want the zigzag line rotated about the origin and not the default center of the line.
  2. You must also scale your zigzags by dividing by 120.

Of course, it can also be done by combining the stream plot with a correctly specified graphic using Show.

s1 = StreamPlot[{1/(x + 1), 1/(y + 1)}, {x, 0, 1}, {y, 0, 1}];
s2 = 
  Graphics @ Rotate[Line[Table[{n, (-1)^n}, {n, 120}]/120], 90 °, {0, 0}];
Show[{s1, s2}]

This produces the same image as the previous code.

| improve this answer | |
  • $\begingroup$ Thank you so much for your helpful comments. $\endgroup$ – user14750 Apr 25 at 9:21

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.