Message Boards Message Boards

1
|
2469 Views
|
6 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Plot range prevents placement of graphic elements

Posted 1 year ago

The plot range prevents graphics elements from being placed outside the plot range. Example: Sine should only be plotted between -Pi and +Pi. But I want to place an arrow from 2Pi to 3Pi.

POSTED BY: Bernd Wichmann
6 Replies

[Answer courtesy of ChatGPT]

Here is an example of how to create a plot of the function sin(x) for x running from -π to π, with an additional arrow starting from (2π,0) and ending at (3π,0) and a plot range from -π to 3π using the Wolfram Language:

Plot[Sin[x], {x, -Pi, Pi}, 
  PlotRange->{{-Pi,3 Pi},{-1,1}},
  Epilog -> {Arrow[{{2 Pi, 0}, {3 Pi, 0}}]}]

This will create a plot of the function Sin[x] for x running from -π to π. The Epilog option is used to add additional graphical elements to the plot, in this case an arrow is added to the plot by using Arrow[{{2 Pi, 0}, {3 Pi, 0}}]. This creates an arrow starting from point (2π,0) and ending at point (3π,0) The PlotRange option is used to set the range of the x and y axis of the plot. In this case, the x-axis range is set to {-π,3π} and y-axis to {-1,1}. The plot will show the sin(x) curve for x from -π to π, an arrow starting from (2π,0) and ending at (3π,0) and the range of x-axis from -π to 3π and y-axis from -1 to 1.

POSTED BY: Arnoud Buzing

Many thanks for the detailed explanation

POSTED BY: Bernd Wichmann
Posted 1 year ago

Using Show to combine sine curve and arrow:

Show[
  Plot[Sin[x],{x,-Pi,Pi}],
  Graphics@Arrow[{{2 Pi,0.5},{3 Pi,0.5}}],
  PlotRange->All
]
POSTED BY: Hans Milton

Or using Epilog

epilog = {Red, Thick, Arrow[{{2 Pi, 0}, {3 Pi, 0}}]};
ticks = Range[-Pi, 3 Pi, Pi/2];

Plot[Sin[x], {x, -Pi, Pi},
 PlotRange -> {{-Pi, 3 Pi}, Automatic},
 Ticks -> {ticks},
 Epilog -> epilog]

enter image description here

POSTED BY: Rohit Namjoshi

Thanks

POSTED BY: Bernd Wichmann
Posted 23 days ago

For me this does not work, in the sense that, if I use (say) "{3 Pi, 10}" instead of "{3 Pi, 0}" in epilog, then the arrow is not fully displayed. I have to replace "Automatic" by the explicit range for this to work.

POSTED BY: Alain Cochard
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract