I wrote an animation with Mathematica 8.04 and saved it as myfile.cdf. It plays nicely on my computer which has mathematica installed. If I play this on a different computer with only Mathematica cdf player installed, it only plays a fraction of the images. There is a command like Show[Graphical object1,Graphical object2, ... ].
I get an error Message from the CDF Player saying
"Show Gcomb: Could not combine Graphics objects in Show[..."
Does anybody know a solution?
EDIT: requested code
\[Phi] = -\[Pi]/6;
A2 = 1.5;
Kreis = ParametricPlot[{2.5 Cos[ t], 2.5 Sin[t]}, {t, 0,
2 \[Pi]},(*AspectRatio->1,*)
PlotStyle -> {{Thickness[.005], RGBColor[1, 1, 1]}},
AxesLabel -> {"Re", "Im"}, Ticks -> {{-3, 3}, {-3, 3}},
ImageSize -> {338, 338}];
sinus1 = Plot[Sin[x], {x, 0, 2 \[Pi]} ,
PlotStyle -> {{Thickness[.005], RGBColor[1, 0, 0]}},
Ticks -> {{0, \[Pi]/2, \[Pi], 3 \[Pi]/2, 2 \[Pi](*,5\[Pi]/2,3\[Pi],
7\[Pi]/2,4\[Pi]*)}, {-3, -1, 1, 3}}, AxesLabel -> {"t", ""},
PlotRange -> {{0, 2 \[Pi]}, {-2.5, 2.5}}, ImageSize -> {525, 525}];
sinus2 = Plot[A2 Sin[x - \[Phi]], {x, 0, 2 \[Pi]},
PlotStyle -> {{Thickness[.005], RGBColor[0, 1, 0]}} ];
sinus3 = Plot[A2 Sin[x - \[Phi]] + Sin[x], {x, 0, 2 \[Pi]},
PlotStyle -> {{Thickness[.005], RGBColor[0, 0, 1]}} ,
PlotRange -> {{0, 2 \[Pi]}, {-2.5, 2.5}}];
Kreisbewegung =
Animate[(*\[Phi]3=ArcTan[(Sin[t]+A2 Sin[t-\[Phi]])/(Cos[t]+A2 Cos[
t-\[Phi]])];
A3=Sqrt[(Cos[t]+A2 Cos[t-\[Phi]])^2+(Sin[t]+A2 Sin[t-\[Phi]])^2];*)
GraphicsRow[{Show [Kreis,(*ParametricPlot[{Cos[ s],Sin[s]},{s,0,t},
PlotStyle->{{Thickness[.005],RGBColor[1,0,0]}}],
ParametricPlot[{A2 Cos[ s],A2 Sin[s]},{s,0,t-\[Phi]},
PlotStyle->{{Thickness[.005],RGBColor[0,1,0]}}],
ParametricPlot[{ A3 Cos[s],A3 Sin[s]},{s,0,\[Phi]3},
PlotStyle->{{Thickness[.005],RGBColor[0,0,1]}}],*)
Graphics[{
Red, Arrowheads[.05], Arrow[{{0, 0}, {Cos[t], Sin[t]}}],
{ Thickness[.0015], Red, Line[{{Cos[t], 0}, {Cos[t], Sin[t]}}]},
Green, Arrowheads[.05],
Arrow[{{0, 0}, {A2 Cos[t - \[Phi]], A2 Sin[t - \[Phi]]}}],
{Thickness[.0015], Green,
Line[{{A2 Cos[t - \[Phi]], 0}, {A2 Cos[t - \[Phi]],
A2 Sin[t - \[Phi]]}}]},
Blue, Arrowheads[.05],
Arrow[{{0, 0}, {Cos[t] + A2 Cos[t - \[Phi]],
Sin[t] + A2 Sin[t - \[Phi]]}}],
{Thickness[.0015],
Blue,
Line[{{Cos[t] + A2 Cos[t - \[Phi]],
0}, {Cos[t] + A2 Cos[t - \[Phi]],
Sin[t] +
A2 Sin[t - \[Phi]]}}]},
Axes -> True, AxesOrigin -> {0, 0}, Ticks -> None ,
PlotRange -> {{-3, 3}, {-3, 3}}, AxesLabel -> {y, x},
AspectRatio -> 1/1}]],
Show[sinus1, sinus2, sinus3,
Graphics[{Thickness[.0015], Green,
Line[{{t, 0}, {t, A2 Sin[t - \[Phi]]}}],
RGBColor[0, 1, 0], PointSize[0.013],
Point[{t, A2 Sin[ t - \[Phi]]}],
Thickness[.0015], Red,
Line[{{t, 0}, {t, Sin[t]}}],
RGBColor[1, 0, 0], PointSize[0.013],
Point[{t, Sin[t]}],
Thickness[.0015], Blue,
Line[{{t, 0}, {t, Sin[t] + A2 Sin[ t - \[Phi]]}}],
RGBColor[0, 0, 1], PointSize[0.013],
Point[{t, Sin[t] + A2 Sin[ t - \[Phi]]}]
} ]
]
}], {t, 0, 2 \[Pi]}, AnimationRate -> 0.01]
Here is a version that should work. As mentioned in the comments your CDF code needs to work without evaluating a line of code.
\[Phi] = -\[Pi]/6;
A2 = 1.5;
Kreis = ParametricPlot[{2.5 Cos[t], 2.5 Sin[t]}, {t, 0,
2 \[Pi]},(*AspectRatio->1,*)
PlotStyle -> {{Thickness[.005], RGBColor[1, 1, 1]}},
AxesLabel -> {"Re", "Im"}, Ticks -> {{-3, 3}, {-3, 3}},
ImageSize -> {338, 338}];
sinus1 = Plot[Sin[x], {x, 0, 2 \[Pi]},
PlotStyle -> {{Thickness[.005], RGBColor[1, 0, 0]}},
Ticks -> {{0, \[Pi]/2, \[Pi], 3 \[Pi]/2, 2 \[Pi](*,5\[Pi]/2,3\[Pi],
7\[Pi]/2,4\[Pi]*)}, {-3, -1, 1, 3}}, AxesLabel -> {"t", ""},
PlotRange -> {{0, 2 \[Pi]}, {-2.5, 2.5}},
ImageSize -> {525, 525}]; sinus2 =
Plot[A2 Sin[x - \[Phi]], {x, 0, 2 \[Pi]},
PlotStyle -> {{Thickness[.005], RGBColor[0, 1, 0]}}];
sinus3 = Plot[A2 Sin[x - \[Phi]] + Sin[x], {x, 0, 2 \[Pi]},
PlotStyle -> {{Thickness[.005], RGBColor[0, 0, 1]}},
PlotRange -> {{0, 2 \[Pi]}, {-2.5, 2.5}}];
Manipulate[
(*\[Phi]3=ArcTan[(Sin[t]+A2 Sin[t-\[Phi]])/(Cos[t]+A2 Cos[t-\[Phi]])];
A3=Sqrt[(Cos[t]+A2 Cos[t-\[Phi]])^2+(Sin[t]+A2 Sin[t-\[Phi]])^2];*)
GraphicsRow[{Show[Kreis,(*ParametricPlot[{Cos[s],Sin[s]},{s,0,t},
PlotStyle->{{Thickness[.005],RGBColor[1,0,0]}}],
ParametricPlot[{A2 Cos[s],A2 Sin[s]},{s,0,t-\[Phi]},
PlotStyle->{{Thickness[.005],RGBColor[0,1,0]}}],
ParametricPlot[{A3 Cos[s],A3 Sin[s]},{s,0,\[Phi]3},
PlotStyle->{{Thickness[.005],RGBColor[0,0,1]}}],*)
Graphics[{Red, Arrowheads[.05],
Arrow[{{0, 0}, {Cos[t], Sin[t]}}], {Thickness[.0015], Red,
Line[{{Cos[t], 0}, {Cos[t], Sin[t]}}]}, Green, Arrowheads[.05],
Arrow[{{0, 0}, {A2 Cos[t - \[Phi]],
A2 Sin[t - \[Phi]]}}], {Thickness[.0015], Green,
Line[{{A2 Cos[t - \[Phi]], 0}, {A2 Cos[t - \[Phi]],
A2 Sin[t - \[Phi]]}}]}, Blue, Arrowheads[.05],
Arrow[{{0, 0}, {Cos[t] + A2 Cos[t - \[Phi]],
Sin[t] + A2 Sin[t - \[Phi]]}}], {Thickness[.0015], Blue,
Line[{{Cos[t] + A2 Cos[t - \[Phi]],
0}, {Cos[t] + A2 Cos[t - \[Phi]],
Sin[t] + A2 Sin[t - \[Phi]]}}]}, Axes -> True,
AxesOrigin -> {0, 0}, Ticks -> None,
PlotRange -> {{-3, 3}, {-3, 3}}, AxesLabel -> {y, x},
AspectRatio -> 1/1}]],
Show[sinus1, sinus2, sinus3,
Graphics[{Thickness[.0015], Green,
Line[{{t, 0}, {t, A2 Sin[t - \[Phi]]}}], RGBColor[0, 1, 0],
PointSize[0.013], Point[{t, A2 Sin[t - \[Phi]]}],
Thickness[.0015], Red, Line[{{t, 0}, {t, Sin[t]}}],
RGBColor[1, 0, 0], PointSize[0.013], Point[{t, Sin[t]}],
Thickness[.0015], Blue,
Line[{{t, 0}, {t, Sin[t] + A2 Sin[t - \[Phi]]}}],
RGBColor[0, 0, 1], PointSize[0.013],
Point[{t, Sin[t] + A2 Sin[t - \[Phi]]}]}]]}], {t, 0, 2 \[Pi]},
SaveDefinitions -> True]
Related
I would like to represent a Catenary-curve in Mathematica, and then allow the user to Manipulate each of the parameters, like the Hanging-Points' position (A,B), the cable's weight, the force of gravity etc.?
I would do it like this:
First, define the catenary:
catenary[x_] := a*Cosh[(x - c)/a] + y
Now I can either find the parameters a, c and y of this curve numerically, using FindRoot:
Manipulate[
Module[{root},
(
root = FindRoot[
{
catenary[x1] == y1,
catenary[x2] == y2
} /. {x1 -> pt[[1, 1]], y1 -> pt[[1, 2]], x2 -> pt[[2, 1]], y2 -> pt[[2, 2]], a -> \[Alpha]},
{{y, 0}, {c, 0}}];
Show[
Plot[catenary[x] /. root /. a -> \[Alpha], {x, -2, 2},
PlotRange -> {-3, 3}, AspectRatio -> 3/2],
Graphics[{Red, Point[pt]}]]
)], {{\[Alpha], 1}, 0.001, 10}, {{pt, {{-1, 1}, {1, 1}}}, Locator}]
Alternatively, you could solve for the parameters exactly:
solution = Simplify[Solve[{catenary[x1] == y1, catenary[x2] == y2}, {y, c}]]
and then use this solution in the Manipulate:
Manipulate[
(
s = (solution /. {x1 -> pt[[1, 1]], y1 -> pt[[1, 2]],
x2 -> pt[[2, 1]], y2 -> pt[[2, 2]], a -> \[Alpha]});
s = Select[s,
Im[c /. #] == 0 &&
Abs[pt[[1, 2]] - catenary[pt[[1, 1]]] /. # /. a -> \[Alpha]] <
10^-3 &];
Show[
Plot[catenary[x] /. s /. a -> \[Alpha], {x, -2, 2},
PlotRange -> {-3, 3}, AspectRatio -> 3/2],
Graphics[{Red, Point[pt]}]]
), {{\[Alpha], 1}, 0.001, 10}, {{pt, {{-1., 1.}, {1., 0.5}}},
Locator}]
The FindRoot version is faster and more stable, though. Result looks like this:
For completeness' sake: It's also possible to find a catenary through 3 points:
m = Manipulate[
Module[{root},
(
root =
FindRoot[
catenary[#[[1]]] == #[[2]] & /# pt, {{y, 0}, {c, 0}, {a, 1}}];
Show[
Plot[catenary[x] /. root, {x, -2, 2}, PlotRange -> {-3, 3},
AspectRatio -> 3/2],
Graphics[{Red, Point[pt]}]]
)], {{pt, {{-1, 1}, {1, 1}, {0, 0}}}, Locator}]
I'm trying to combine 3 functions graphed on a Plot[] and 1 function graphed on a ParametricPlot[]. My equations are as follows:
plota = Plot[{-2 x, -2 Sqrt[x], -2 x^(3/5)}, {x, 0, 1}, PlotLegend -> {"-2 x", "-2 \!\(\*SqrtBox[\(x\)]\)", "-2 \!\(\*SuperscriptBox[\(x\), \(3/5\)]\)"}]
plotb = ParametricPlot[{2.4056 (u - Sin[u]), 2.4056 (Cos[u] - 1)}, {u,0, 1.40138}, PlotLegend -> {"Problem 3"}]
Show[plota, plotb]
This is the image it gives:
As yoda said, PlotLegends is terrible. However, if you don't mind setting the plot styles manually and repeating them lateron, ShowLegend can help.
plota = Plot[{-2 x, -2 Sqrt[x], -2 x^(3/5)}, {x, 0, 1},
PlotStyle -> {{Red}, {Blue}, {Orange}}];
plotb = ParametricPlot[{2.4056 (u - Sin[u]), 2.4056 (Cos[u] - 1)}, {u, 0, 1.40138},
PlotStyle -> {{Black}}];
And now
ShowLegend[Show[plota, plotb],
{{{Graphics[{Red, Line[{{0, 0}, {1, 0}}]}], Label1},
{Graphics[{Blue, Line[{{0, 0}, {1, 0}}]}], Label2},
{Graphics[{Orange, Line[{{0, 0}, {1, 0}}]}], Label3},
{Graphics[{Black, Line[{{0, 0}, {1, 0}}]}], Label4}},
LegendSize -> {0.5, 0.5}, LegendPosition -> {0.5, -0.2}}]
which will give you this:
You can also write some simple functions to make this a little less cumbersome, if you deal with this problem often.
Well, the root cause of the error is the PlotLegends package, which is a terrible, buggy package. Removing that, Show combines them correctly:
plota = Plot[{-2 x, -2 Sqrt[x], -2 x^(3/5)}, {x, 0, 1}]
plotb = ParametricPlot[{2.4056 (u - Sin[u]), 2.4056 (Cos[u] - 1)}, {u,
0, 1.40138}]
Show[plota, plotb]
You can see Simon's solution here for ideas to label your different curves without using PlotLegends. This answer by James also demonstrates why PlotLegends has the reputation it has...
You can still salvage something with the PlotLegends package. Here's an example using ShowLegends that you can modify to your tastes
colors = {Red, Green, Blue, Pink};
legends = {-2 x, -2 Sqrt[x], -2 x^(3/5), "Problem 3"};
plota = Plot[{-2 x, -2 Sqrt[x], -2 x^(3/5)}, {x, 0, 1},
PlotStyle -> colors[[1 ;; 3]]];
plotb = ParametricPlot[{2.4056 (u - Sin[u]), 2.4056 (Cos[u] - 1)}, {u,
0, 1.40138}, PlotStyle -> colors[[4]]];
ShowLegend[
Show[plota,
plotb], {Table[{Graphics[{colors[[i]], Thick,
Line[{{0, 0}, {1, 0}}]}], legends[[i]]}, {i, 4}],
LegendPosition -> {0.4, -0.15}, LegendSpacing -> 0,
LegendShadow -> None, LegendSize -> 0.6}]
As the other answers pointed out, the culprit is PlotLegend. So, sometimes is useful to be able to roll your own plot legends:
plotStyle = {Red, Green, Blue};
labls = {"a", "b", "Let's go"};
f[i_, s_] := {Graphics[{plotStyle[[i]], Line[{{0, 0}, {1, 0}}]},
ImageSize -> {15, 10}], Style[labls[[i]], s]};
Plot[{Sin[x], Sin[2 x], Sin[3 x]}, {x, 0, 2 Pi},
PlotStyle -> plotStyle,
Epilog ->
Inset[Framed[Style#Column[{Grid[Table[f[i, 15], {i, 1, 3}]]}]],
Offset[{-2, -2}, Scaled[{1, 1}]], {Right, Top}],
PlotRangePadding -> 1
]
Please consider the following, from the followings from
Can we generate "foveated Image" in Mathematica
Clear[acuity];
acuity[distance_, x_, y_, blindspotradius_] :=
With[{\[Theta] = ArcTan[distance, Sqrt[x^2 + y^2]]},
Clip[(Chop#Exp[-Abs[\[Theta]]/(15. Degree)] - .05)/.95,
{0,1}] (1.-Boole[(x + 100.)^2 + y^2 <= blindspotradius^2])]
Plot3D[acuity[250., x, y, 9], {x, -256, 256}, {y, -256, 256},
PlotRange -> All, Axes -> False, PlotPoints -> 40,
ExclusionsStyle -> Automatic, Boxed -> False, Mesh -> None]
How could I add the photo below on the X & Y plane. Then have the surface plotted transparent.
Is it possible ? (image obtained with a solution in the question mentioned above).
i = Import["http://i.stack.imgur.com/0EizO.png"];
p = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
Show#{
Plot3D[
acuity[250., x, y, 9], {x, -256, 256}, {y, -256, 256},
PlotRange -> All, PlotPoints -> 40,ExclusionsStyle -> Automatic,Axes -> False,
Boxed -> False, Mesh -> None, PlotStyle -> Directive[Opacity[0.5]]],
Graphics3D[{Texture[i],
Polygon[Join[#, {0}] & /# (2 p - 1) 256, VertexTextureCoordinates -> p]}
]}
Edit
Dealing with AspectRatio[], as requested in your comments:
p = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
r = First##/Last## &#Dimensions#ImageData#i;
a = 1.4;
Show#{Plot3D[
acuity[250., a x, a y, 9], {x, -256 , 256 }, {y, -256 r , 256 r },
PlotRange -> All, PlotPoints -> 40, ExclusionsStyle -> Automatic,
Axes -> False, Boxed -> False, Mesh -> None,
PlotStyle -> Directive[Opacity[0.5]], AspectRatio -> r],
Graphics3D[{Texture[i],
Polygon[{{-256 , -256 r, 0}, { 256 , -256 r , 0},
{ 256 , 256 r, 0}, {-256 , 256 r, 0}},
VertexTextureCoordinates -> p]}]}
Is it possible to create graphics of spherical co-ordinate system like this in mathematica or should I use photoshop? I'm asking because I want a high resolution graphic, but lot of the files on internet are grainy when zoomed.
Here is the image:
The figure is made up of simple geometric shapes and these can be easily recreated in Mathematica using equations. Here is one that is close to this plot, which IMO is less cluttered than the above, but you can always use these ideas to recreate your image exactly.
Clear[ellipsePhi, ellipseTheta, circle]
circle[x_] = {Cos[x], Sin[x]};
ellipsePhi[x_, a_: - Pi/2] = {Cos[x - a]/3, Sin[x + a]};
ellipseTheta[x_, a_: 0] = {Cos[x + a], Sin[-x - a]/2};
(*Main circle*)
ParametricPlot[circle[x], {x, 0, 2 Pi},
PlotStyle -> Black,
Epilog -> First /# {
(*Ellipses*)
ParametricPlot[{ellipsePhi[x], ellipsePhi[-x], ellipseTheta[-x],
ellipseTheta[x]}, {x, 0, Pi},
PlotStyle -> {{Black, Dashed}, Black}],
(*Co-ordinate axes*)
Graphics[
Table[GeometricTransformation[{Arrowheads[0.03],
Arrow[{{0, 0}, {1.2, 0}}]},
ReflectionMatrix[circle[x]]], {x, {Pi/2, -Pi/4, Pi/8}}]],
(*mark point, rho, phi & theta directions*)
ParametricPlot[{ellipsePhi[x, Pi/2], ellipseTheta[-x, 13 Pi/20]}, {x,
0, Pi/4},
PlotStyle -> {{Red, Thick}, {Blue, Thick}}] /.
Line[x__] :> Sequence[Arrowheads[0.03], Arrow[x]],
Graphics[{{Directive[Darker#Green, Thick], Arrowheads[0.03],
Arrow[{{0, 0}, ellipsePhi[-3 Pi/4]}]},
{Directive[Purple], Disk[ellipsePhi[-3 Pi/4], 0.02]}}],
(*text*)
Graphics[{
Text[Style["x", Italic, Larger], 1.25 circle[5 Pi/4]],
Text[Style["y", Italic, Larger], 1.25 circle[0]],
Text[Style["z", Italic, Larger], 1.25 circle[Pi/2]],
Text[Style["\[Rho]", Italic, Larger], 0.4 circle[4 Pi/11]],
Text[Style["\[CurlyPhi]", Italic, Larger],
1.1 ellipsePhi[Pi + Pi/5]],
Text[Style["\[Theta]", Italic, Larger],
1.1 ellipseTheta[13 Pi/20 - Pi/8]],
Text[Style["P", Italic, Larger], 1.2 ellipsePhi[-3 Pi/4 + Pi/24]]}]
},
Axes -> False, PlotRange -> 1.3 {{-1, 1}, {-1, 1}}
]
which gives you this
Although it is possible to set the angles & arrows precisely, in some places (e.g., 13 Pi/20), I've only roughly approximated it. You really can't tell the difference in the final figure, but if you're picky you can change them and fix the positions exactly.
This alternative solution has the advantage of being created using 3D directives. As such, it was easy to wrap inside a Manipulate and you can drag it with your mouse to change the viewpoint:
Manipulate[
Module[{x = Sin[\[Phi]] Cos[\[Theta]], y = Sin[\[Phi]] Sin[\[Theta]],
z = Cos[\[Phi]]},
Show[
ParametricPlot3D[
{{Cos[t], Sin[t], 0},
{0, Sin[t], Cos[t]},
{Sin[t], 0, Cos[t]}},
{t, 0, 2 \[Pi]}, PlotStyle -> Black, Boxed -> False,
Axes -> False, AxesLabel -> {"x", "y", "z"}],
ParametricPlot3D[0.5*{Cos[t], Sin[t], 0}, {t, 0, \[Theta]}],
ParametricPlot3D[
RotationTransform[\[Theta], {0, 0, 1}][{Sin[t]/2, 0,
Cos[t]/2}], {t, 0, \[Phi]}],
Graphics3D[{
{{Blue, Thick,
Arrow[{{0, 0, 0}, #}] & /# {{1, 0, 0}, {0, 1, 0}, {0, 0,
1}, {x, y, z}}},
{Opacity[0.1],
Red, Polygon[{{0, 0, 0}, {x, y, 0}, {x, y, z}}],
Green, Polygon[{{0, 0, 0}, {x, 0, 0}, {x, y, 0}}]}},
{Opacity[0.05], Sphere[{0, 0, 0}]},
{Text["O", {-.03, -.03, -.03}],
Text["X", {1.1, 0, 0}],
Text["Q", {x, y, 0}, {1, 1}],
Text["P", {x, y, z}, {0, -1}],
Text["Y", {0, 1.1, 0}],
Text["Z", {0, 0, 1.1}],
Text["r", {x/2, y/2, 0}, {1, 1}],
Text[
"\[Theta]", {Cos[\[Theta]/2]/2, Sin[\[Theta]/2]/2, 0}, {1,
1}],
Text["\[Phi]",
RotationTransform[\[Theta], {0, 0, 1}][{Sin[\[Phi]/2]/2, 0,
Cos[\[Phi]/2]/2}], {1, 1}]}}]]],
{{\[Phi], \[Pi]/4}, 0.01, \[Pi]/2}, {{\[Theta], \[Pi]/4}, 0.01,
2 \[Pi]}]
Is it possible to zoom into a region and display it as a subplot within the same plot? Here is my primitive attempt at freehand graphics, to illustrate my question:
I can think of using Plot, and then Epilog, but then I get lost in the positioning and in giving the plot its own origin (When I try Epilog on Plot, the new plot lays on top of the old one, using the old one's origin).
Also, it would be nice if the positioning of the subplot can be input, as different curves have different "empty regions" that can be used to position the image.
I've seen this in several articles and I can do this in MATLAB, but I have no clue how to do it in mma.
Use Inset. Here's an example:
f[x_] = Sum[Sin[3^n x]/2^n, {n, 0, 20}];
x1 = x /. FindRoot[f[x] == -1, {x, -2.1}];
x2 = x /. FindRoot[f[x] == -1, {x, -1.1, -1}];
g = Plot[f[x], {x, x1, x2}, AspectRatio -> Automatic,
Axes -> False, Frame -> True, FrameTicks -> None];
{y1, y2} = Last[PlotRange /. FullOptions[g]];
Plot[Sum[Sin[3^n x]/2^n, {n, 0, 20}], {x, -Pi, Pi},
Epilog -> {Line[{
{{x2, y2 + 0.1}, {-0.5, 0.5}}, {{x1, y2 + 0.1}, {-3.5, 0.5}},
{{x1, y1}, {x2, y1}, {x2, y2 + 0.1}, {x1, y2 + 0.1}, {x1,
y1}}}],
Inset[g, {-0.5, 0.5}, {Right, Bottom}, 3]},
PlotRange -> {{-4, 4}, {-3, 3}}, AspectRatio -> Automatic]
And, borrowing from belisarius' code, you can also select the focus of your inset interactively by selecting a position at the x-axis:
imgsz = 400;
f[x_] := Piecewise[{{Sin#x, Abs#x > .1}, {Sin[100 x], Abs[x] <= 0.1}}];
Manipulate[
Plot[f[x], {x, -3, 3}, PlotRange -> {{-3, 3}, {-2, 5}},
ImageSize -> imgsz,
Epilog ->
Inset[Plot[f[y], {y, p[[1]] - .3, p[[1]] + 0.3}, PlotStyle -> Red,
Axes -> False, Frame -> True, ImageSize -> imgsz/3], {1.5, 3}]],
{{p, {0, 0}}, Locator, Appearance -> None}]
or, if you also want to place the inset interactively:
Manipulate[
Plot[f[x], {x, -3, 3}, PlotRange -> {{-3, 3}, {-2, 5}},
ImageSize -> imgsz,
Epilog ->
Inset[Plot[f[y], {y, p[[1, 1]] - .3, p[[1, 1]] + 0.3},
PlotStyle -> Red, Axes -> False, Frame -> True,
ImageSize -> imgsz/3], p[[2]]]],
{{p, {{0, 0}, {1.5, 3}}}, Locator, Appearance -> None}]
EDIT
one more alternative based on dbjohn's question:
imgsz = 400;
f[x_] := Piecewise[{{Sin#x, Abs#x > .1}, {Sin[100 x], Abs[x] <= 0.1}}];
Manipulate[
Plot[f[x], {x, -3, 3}, PlotRange -> {{-3, 3}, {-2, 5}},
ImageSize -> imgsz,
Epilog ->
Inset[Plot[f[y], {y, p[[1]] - .3, p[[1]] + 0.3}, PlotStyle -> Red,
Axes -> False, Frame -> True, ImageSize -> imgsz/3],
Scaled[zw]]], {{p, {0, 0}}, Locator,
Appearance -> None}, {{zw, {0.5, 0.5}, "Zoom window"}, Slider2D}]
Just a kickstart:
imgsz = 400;
f[x_] := Piecewise[{{Sin#x, Abs#x > .1}, {Sin[100 x], Abs[x] <= 0.1}}];
Plot[f[x], {x, -3, 3}, PlotRange -> {{-5, 5}, {-5, 5}},
ImageSize -> imgsz, Epilog ->
Inset[Plot[f[y], {y, -.3, 0.3}, PlotStyle -> Red, Axes -> False,
Frame -> True, ImageSize -> imgsz/3], {3, 3}]]
I find this an area in need of better built in tools. I have been working on this solution based on a demo here. I prefer to have the zoomed image and unzoomed image separated and as a bonus I added a presentable area where one could put relevant text or equations. For different functions the aspect ratio may need to be tweaked manually.
(f[x_] := x^2;
; xMin = -5; yMin = -5; xMax = 5; yMax = 5;
Manipulate[
Grid[{{LocatorPane[{a},
Plot[f[x], {x, xMin, xMax},
PlotRange -> {{xMin, xMax }, {yMin, yMax}},
ImageSize -> Medium, AspectRatio -> 1, AxesOrigin -> {0, 0}]],
Plot[f[x], {x, (a[[1]]) + xMin*mag, (a[[1]]) + xMax*mag},
PlotRange -> {{(a[[1]]) + xMin*mag, (a[[1]]) +
xMax*mag}, {(a[[2]]) + yMin*mag, (a[[2]]) + yMax*mag}},
ImageSize -> Medium, AspectRatio -> 1, AxesOrigin -> {0, 0}],
Item[StringForm["This is a suitable area to put any text.
Value of A is :
`1` ", a], Alignment -> {Left, Top}]}}, Frame -> All,
ItemSize -> All,
Spacings -> 5], {{a, {0, 0}}, {xMin, yMin}, {xMax, yMax}, Locator,
Appearance ->
Graphics[{Yellow, Opacity[.2],
Rectangle[Scaled[{.5 - (mag/2), .5 - (mag/2)}],
Scaled[{.5 + (mag/2), .5 + (mag/2)}]]}]}, {{mag, .5,
"Magnification"}, 0.01, 1, Appearance -> "Labeled"}])
(f[x_] :=
Piecewise[{{Sin#x, Abs#x > .1}, {Sin[100 x], Abs[x] <= 0.1}}];
; xMin = -3; yMin = -3; xMax = 3; yMax = 3;
Manipulate[
Grid[{{LocatorPane[{a},
Plot[f[x], {x, xMin, xMax},
PlotRange -> {{xMin, xMax }, {yMin, yMax}},
ImageSize -> Medium, AspectRatio -> 1, AxesOrigin -> {0, 0}]],
Plot[f[x], {x, (a[[1]]) + xMin*mag, (a[[1]]) + xMax*mag},
PlotRange -> {(*{(a[[1]])+xMin*mag,(a[[1]])+xMax*
mag},*){(a[[2]]) + yMin*mag, (a[[2]]) + yMax*mag}},
ImageSize -> Medium, AspectRatio -> 1, AxesOrigin -> {0, 0},
Frame -> True],
Item[StringForm["This is a suitable area to put any text.
Value of A is :
`1` ", a], Alignment -> {Left, Top}]}}, Frame -> All,
ItemSize -> All,
Spacings -> 5], {{a, {0, 0}}, {xMin, yMin}, {xMax, yMax}, Locator,
Appearance ->
Graphics[{Yellow, Opacity[.2],
Rectangle[Scaled[{.5 - (mag/2), .5 - (mag/2)}],
Scaled[{.5 + (mag/2), .5 + (mag/2)}]]}]}, {{mag, .06,
"Magnification"}, 0.01, 1, Appearance -> "Labeled"}])