Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Combine images, Show[] and its effect on AspectRatio. Plot, Epilog, Circle, Arc

103 views
Skip to first unread message

Nasser M. Abbasi

unread,
Dec 1, 2009, 4:15:05 AM12/1/09
to
Hello,

This is Version 7, Windows.

I make a plot and Mathematica seems to have a good algorithm for coming up
with an AspectRatio which makes the plot looks good. So when I type

p=Plot[Sin[x],{x,-Pi,Pi}];
AspectRatio/.FullOptions[p]
0.618034

Now, I wanted to add an arc on top of the above plot at some place, say the
origin, so I type

p=Plot[Sin[x],{x,-Pi,Pi},Epilog->Circle[{0,0},.5,{-45 Degree,180 Degree}]];
AspectRatio/.FullOptions[p]
Out[67]= 0.618034
Show[p]

But due to the aspect ratio used for the Plot itself, you can see that the
arc is not circular as I expected. So now I typed

p=Plot[Sin[x],{x,-Pi,Pi},AspectRatio->Automatic,Epilog->Circle[{0,0},.5,{-45
Degree,180 Degree}]];
AspectRatio/.FullOptions[p]
0.31831
Show[p]

Now, the arc is seen as circular, but I lost the good aspect ratio which
made my Plot look good.

So, I was trying to find how to keep the original Aspect ratio for the plot,
but keep the arc come up as circular and not turn to some sort of elliptic
shape as would be the case without the use of Automatic.

I also tried Show[g1,g2] but depending on the order, the AspectRatio changes
(because Show[] uses information from the first object). So that did not
help.

So, my problem is that I need to make the plot using the Mathematica
calculated AspectRatio, but also add an or circle and make that show as a
circle on the top of the earlier plot, and not have its AspectRatio changed
by adding the new object. Using AspectRatio->Automatic is not an option, as
it made my overall plot look not good.

Graphics[] has 100's of options, and I am looking at them now, may be there
is something hidden there, but I am not seeing anything yet.

Thanks
--Nasser


dh

unread,
Dec 1, 2009, 6:28:20 AM12/1/09
to

Nasser M. Abbasi wrote:

> Hello,

>

>

>

> AspectRatio/.FullOptions[p]

> 0.618034

>

> origin, so I type

>

> AspectRatio/.FullOptions[p]

> Out[67]= 0.618034

> Show[p]

>

>

> Degree,180 Degree}]];

> AspectRatio/.FullOptions[p]

> 0.31831

> Show[p]

>

>

>

> help.

>

>

>

> Thanks

> --Nasser

>

>

Hi Nasser,

the circle is drawn in the coordinate system of the plot. Therefore, you

need to draw the circle as an ellipss in the "Plot" coordinate system.

This can be done by a scaling transformation that takes care of the

aspect ratio:

cir = Circle[{0, 0}, 1, {-45 Degree, 180 Degree}];

pl = Plot[Sin[x], {x, -Pi, Pi}];

asp = AspectRatio /. FullOptions[pl];

tr = ScalingTransform[{1/asp, 1}];

cir = Graphics@GeometricTransformation[cir, tr];

Show[pl, cir]

Albert Retey

unread,
Dec 2, 2009, 6:27:52 AM12/2/09
to
Nasser M. Abbasi schrieb:

I think that the main problem is that you want the line to look like a
circle, not to be a circle in the coordinates of the plot. So you need
to use Scaled, along with the scaling others have suggested:

p = Plot[Sin[x], {x, -Pi, Pi},
Epilog ->
Circle[{0, 0},
Scaled[0.25 {1/GoldenRatio, 1}], {-45 Degree, 180 Degree}]]

of course you could also use AbsoluteOptions to find the actual
AspectRatio and to the scaling with that value....

hth,

albert

Nasser M. Abbasi

unread,
Dec 2, 2009, 6:28:45 AM12/2/09
to
I think I found a solution, and this works for any plot ranges, the idea is
to use Epilog and Inset.

here it is.


(* make an arc with an arrow at the end *)
r=3;

data = Table[{r*Cos[theta], r*Sin[theta]},
{theta, -45*Degree, 180*Degree, 1*Degree} ];

arrow= {Arrowheads[Medium],Arrow[Line[data]]};


(*now place at an center of a plot, using Epilog and Inset, change plot
ranges to see if it remains circular *)

Plot[Sin[x],{x, -Pi, Pi},

Epilog->Inset[ Graphics[arrow],{0,0},{0,0},r]]

Plot[Sin[x],{x, -3 Pi,3 Pi},
Epilog->Inset[ Graphics[arrow],{0,0},{0,0},r]]

Plot[Sin[x],{x, - 6Pi, 6Pi},
Epilog->Inset[ Graphics[arrow],{0,0},{0,0},r]]

Plot[x^3,{x, -10, 10},
Epilog->Inset[ Graphics[arrow],{0,0},{0,0},r]]


so far so good!

--Nasser


Nasser M. Abbasi

unread,
Dec 2, 2009, 6:31:00 AM12/2/09
to
"dh" <d...@metrohm.com> wrote in message news:4B14FCD...@metrohm.com...

>>
> Hi Nasser,
> the circle is drawn in the coordinate system of the plot. Therefore, you
> need to draw the circle as an ellipss in the "Plot" coordinate system.
> This can be done by a scaling transformation that takes care of the aspect
> ratio:
>
> cir = Circle[{0, 0}, 1, {-45 Degree, 180 Degree}];
> pl = Plot[Sin[x], {x, -Pi, Pi}];
> asp = AspectRatio /. FullOptions[pl];
> tr = ScalingTransform[{1/asp, 1}];
> cir = Graphics@GeometricTransformation[cir, tr];
> Show[pl, cir]
>

Hi Daniel;

Notice what I changed the plot range, the circle no longer comes out
circular looking. Below I made the plot to go from -5Pi to +5Pi

cir=Circle[{0,0},1,{-45 Degree,180 Degree}];
pl=Plot[Sin[x],{x,-5Pi,5 Pi}];
asp=AspectRatio/.FullOptions[pl];
tr=ScalingTransform[{1/asp,1}];
cir=Graphics@GeometricTransformation[cir,tr];
Show[pl,cir]

It happens to work ok when the plot range was {-Pi,Pi} (same for the post I
just send, which worked for only -Pi,Pi, so I still need to work on this
more!), but not for other plots ranges.

thanks
--Nasser

Nasser M. Abbasi

unread,
Dec 2, 2009, 6:31:11 AM12/2/09
to

>
> The original aspect ratio is
>
> 1/GoldenRatio // N
>
> 0.618034
>
> If you want a circle using that aspect ratio, then draw an ellipse

>
> p = Plot[Sin[x], {x, -Pi, Pi},
> Epilog -> Circle[{0, 0}, .5 {GoldenRatio, 1},
> {-45 Degree, 180 Degree}]]
>
>
> Bob Hanlon
>
>

Hi;

The above works for {-Pi,Pi}, when I changed the plot range, it no longer
comes out as a circle:

pl=Plot[Sin[x],{x,-3 Pi,3 Pi}];
asp=AspectRatio/.FullOptions[pl];

p=Plot[Sin[x],{x,-3 Pi,3 Pi},Epilog->Circle[{0,0},.5 {1/asp,1},{-45
Degree,180 Degree}]]

--Nasser


David Park

unread,
Dec 2, 2009, 6:36:50 AM12/2/09
to
Nasser,

The problem with the replies I saw this morning is that the arc is still not
circular. That is because (I think) AspectRatio does not refer to the Frame
of the plot but to the overall plot box that also contains the tick labels.
This makes it more difficult and you have to guess at the proper circle
scaling.

The following is a Presentations solution that uses an Automatic
AspectRatio, which gets the Circle right, then stretches the Sin curve to
give the approximate appearance it would have with a 1/GoldenRatio
AspectRatio, and then uses CustomTicks to put the correct y ticks on the
plot.

Needs["Presentations`Master`"]

yticks = CustomTicks[GoldenRatio # &, {-1, 1, .5, 5}];
Draw2D[
{Draw[GoldenRatio Sin[x], {x, -\[Pi], \[Pi]}],
Circle[{0, 0}, 1, {-45 Degree, 180 Degree}]},
AspectRatio -> Automatic,
Frame -> True,
FrameTicks -> {{yticks, yticks // NoTickLabels}, {Automatic,
Automatic}},
ImageSize -> 400]


David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/

Hello,

Thanks
--Nasser


dh

unread,
Dec 4, 2009, 4:35:57 AM12/4/09
to

Nasser M. Abbasi wrote:

>> Hi Nasser,

>> ratio:

>>

>> Show[pl, cir]

>>

>

> Hi Daniel;

>

>

> asp=AspectRatio/.FullOptions[pl];

> tr=ScalingTransform[{1/asp,1}];

> cir=Graphics@GeometricTransformation[cir,tr];

> Show[pl,cir]

>

>

> thanks

> --Nasser

>

>

>

Hi Nasser,

you are right, we not only need to take into consideration the aspect

ratio but also the plot range. The solution with inset is certainly

simpler, but for the heck of it, here is a solution:

cir = Circle[{0, 0}, 1, {-45 Degree, 180 Degree}];

pl = Plot[Sin[x], {x, -5 Pi, 5 Pi}];

plr = PlotRange /. FullOptions[pl];

asp = AspectRatio /. FullOptions[pl];

plr = (plr[[2, 2]] - plr[[2, 1]])/(plr[[1, 2]] - plr[[1, 1]]);

tr = ScalingTransform[{asp/plr, 1}];

cir = Graphics@GeometricTransformation[cir, tr];

Show[pl, cir]

Daniel

0 new messages