Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #11336 > unrolled thread
| Started by | Gregory Lypny <gregory.lypny@videotron.ca> |
|---|---|
| First post | 2012-08-14 09:04 +0000 |
| Last post | 2012-08-29 05:19 +0000 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Drawing a Line From One Plot to Another Gregory Lypny <gregory.lypny@videotron.ca> - 2012-08-14 09:04 +0000
Re: Drawing a Line From One Plot to Another Vincenzo Carrino <vincent.carrino@gmail.com> - 2012-08-15 07:33 +0000
Re: Drawing a Line From One Plot to Another "Alexander Elkins" <alexander_elkins@hotmail.com> - 2012-08-16 06:06 +0000
Re: Drawing a Line From One Plot to Another E. Martín-Serrano <eMartinSerrano@telefonica.net> - 2012-08-20 08:16 +0000
Re: Drawing a Line From One Plot to Another "Alexander Elkins" <alexander_elkins@hotmail.com> - 2012-08-29 05:19 +0000
| From | Gregory Lypny <gregory.lypny@videotron.ca> |
|---|---|
| Date | 2012-08-14 09:04 +0000 |
| Subject | Drawing a Line From One Plot to Another |
| Message-ID | <k0d4b9$m8b$1@smc.vnet.net> |
Hello everyone, Say I have two plots, y=x^2 and y=2x, aligned vertically using GraphicsColumn. Their domains are aligned because x runs from -3 to +3 in both. I'd like to be able to draw a line from a point in the top graph to a point in the bottom graph. How can I do that? Regards, Gregory
[toc] | [next] | [standalone]
| From | Vincenzo Carrino <vincent.carrino@gmail.com> |
|---|---|
| Date | 2012-08-15 07:33 +0000 |
| Message-ID | <k0fjbs$q7j$1@smc.vnet.net> |
| In reply to | #11336 |
On Tuesday, August 14, 2012 5:04:41 AM UTC-4, Gregory Lypny wrote:
> Hello everyone,
>
>
>
> Say I have two plots, y=x^2 and y=2x, aligned vertically using GraphicsColumn. Their domains are aligned because x runs from -3 to +3 in both. I'd like to be able to draw a line from a point in the top graph to a point in the bottom graph. How can I do that?
>
>
>
> Regards,
>
>
>
> Gregory
If we use the Epilog option on each plot then a line can be drawn on both plots independently. The result would have a gap in the middle though. It is possible to then use the Spacings option on the GraphicsColumn to bring the plots together, but then the plots blend together. Also important is to use ImagePadding to control the width of each plot.
GraphicsColumn[{Plot[x^2, {x, -5, 5}, ImagePadding -> 10, Epilog -> Line[{{3, -100}, {3, 100}}]],
Plot[2*x, {x, -5, 5}, ImagePadding -> 10, Epilog -> Line[{{3, -100}, {3, 100}}]]},
Spacings -> -21]
The other option is to use Show with the GraphicsColumn and Graphics[Line[]]. You have to just play with the coordinates for that line though, very adhoc.
Show[GraphicsColumn[{Plot[x^2, {x, -5, 5}, ImagePadding -> 10], Plot[2*x, {x, -5, 5}, ImagePadding -> 10]}],
Graphics[Line[{{282, -470}, {282, 0}}]]]
Hope that helps.
Cheers,
Vincenzo
[toc] | [prev] | [next] | [standalone]
| From | "Alexander Elkins" <alexander_elkins@hotmail.com> |
|---|---|
| Date | 2012-08-16 06:06 +0000 |
| Message-ID | <k0i2lm$1cf$1@smc.vnet.net> |
| In reply to | #11336 |
It is possible to do this using the Drawing Tools from the Graphics menu on
the output of GraphicsGrid.
Or use Get Coordinates from the context menu on the output of GraphicsGrid
and then go back and add an Epilog option to GraphicsGrid.
For example, based on Bob Hanlan's example:
y1[x_] = x^2;
y2[x_] = 2 x;
pts = {x, y1[x]} /. Solve[y1[x] == y2[x], x];
GraphicsGrid[{{Plot[Evaluate[Tooltip[y1[x]]], {x, -1, 3},
Frame -> True, Axes -> False,
Epilog -> {Text[#, #, {1, -2}] & /@ pts, Red,
AbsolutePointSize[4], Point[pts]}]}, {Plot[
Evaluate[Tooltip[y2[x]]], {x, -1, 3}, Frame -> True,
Axes -> False,
Epilog -> {Text[#, #, {-1, 2}] & /@ pts, Red,
AbsolutePointSize[4], Point[pts]}]}},
Epilog -> {Darker[Green], AbsoluteDashing[{10, 5}],
Arrow[{{113.5, -208.4}, {117.8, -397.4}}],
Arrow[{{272.1, -122.6}, {275.4, -299.6}}]}]
Hope this helps...
"Gregory Lypny" <gregory.lypny@videotron.ca> wrote in message
news:k0d4b9$m8b$1@smc.vnet.net...
> Hello everyone,
>
> Say I have two plots, y=x^2 and y=2x, aligned vertically using
GraphicsColumn. Their domains are aligned because x runs from -3 to +3 in
both. I'd like to be able to draw a line from a point in the top graph to a
point in the bottom graph. How can I do that?
>
> Regards,
>
> Gregory
>
[toc] | [prev] | [next] | [standalone]
| From | E. Martín-Serrano <eMartinSerrano@telefonica.net> |
|---|---|
| Date | 2012-08-20 08:16 +0000 |
| Message-ID | <k0sro5$jn0$1@smc.vnet.net> |
| In reply to | #11336 |
f2[x_]:=2 x
f1[x_]:= x^2
xmin =-3;
xmax= 3;
plotrange1={{-3.3,3.3},{-0.9,9.9}};
plotrange2={{-3.3,3.3},{-6.6,6.6}};
Manipulate[
Module[{isize =300},
xmin =-3;
xmax= 3;
pt11 ={xx, f1[xx]};
pt12 ={xx, plotrange1[[2]][[1]]};
g1 =Show[{Plot[f1[x],{x,xmin,xmax},PlotStyle-> Purple ],
Graphics[{{Red,Dashed, Line[{pt11 ,pt12}]}, Red,PointSize[.02],
Point[pt11], Black, Circle[pt11,Offset[4]]}]}, PlotRange -> plotrange1,
Axes-> True,AxesStyle->{Transparent,LightGray},Ticks->Automatic,Frame->
True,FrameStyle -> {{LightGray, LightGray},{Transparent,
LightGray}},FrameTicks -> False,ImageSize -> isize];
pt21 ={xx, f2[xx]};
pt22 ={xx, plotrange2[[2]][[2]]};
g2=Show[{Plot[f2[x],{x,xmin,xmax},PlotStyle-> Blue ], Graphics[{{Red,Dashed,
Line[{pt21 ,pt22}]}, Red,PointSize[.02], Point[pt21],Black,
Circle[pt21,Offset[4]]}]}, PlotRange -> plotrange2, Axes->
True,AxesStyle->{Transparent,LightGray},Ticks->Automatic,Frame->
True,FrameStyle -> {{LightGray,
LightGray},{LightGray,{Dashed,LightGray}}},FrameTicks -> False,ImageSize ->
isize];
Column[{g1,g2},Center,Spacings->0]],
{{xx,.6,"Current 'x' value"},xmin,xmax, ImageSize->Small}]
(* Try the slider and the Manipulate 'Autorun' *)
[toc] | [prev] | [next] | [standalone]
| From | "Alexander Elkins" <alexander_elkins@hotmail.com> |
|---|---|
| Date | 2012-08-29 05:19 +0000 |
| Message-ID | <k1k8od$90n$1@smc.vnet.net> |
| In reply to | #11336 |
The uGraphicsDecorations function defined below converts the Frame,
Axes and *Ticks Options output by Plot into graphics.
uGraphicsDecorations @@ Plot[...] produces a better and faster result
than can be obtained by FullGraphics[Plot[...]][[1]].
Example usage (a line connects the two plots and remains connected as
their positions and rotations are changed):
Block[{g1, g2, mv1, mv2},
Manipulate[mv1 = {RotationMatrix[t1], pts[[1]]};
mv2 = {RotationMatrix[t2], pts[[2]]};
Graphics[{GeometricTransformation[g1, mv1],
GeometricTransformation[g2, mv2], Red, PointSize[Medium],
Point[AffineTransform[mv1]@{2, 4}], Green,
Point[AffineTransform[mv2]@{2, 4}], Orange,
Line[{AffineTransform[mv1]@{2, 4}, AffineTransform[mv2]@{2, 4}}]},
AspectRatio -> Full, PlotRange -> {{-7, 7}, {-10, 17}}]
, {{t1, 0 , "Angle 1"}, -Pi, Pi}, {{t2, 0 , "Angle 2"}, -Pi,
Pi}, {{pts, {{-2, 6}, {3, -5}}}, Locator},
Initialization :> (g1 = uGraphicsDecorations @@ Plot[x^2, {x, -1, 3}];
g2 = uGraphicsDecorations @@ Plot[2 x, {x, -1, 3}])]]
Please note:
* Styling is not implemented in this example.
* It not fully tested -- the full behavior is not implemented.
* The PlotRange option is supplied in the output of plot.
* The ImagePadding option may be needed for the container to
display tick mark labels which lie outside of the
PlotRange with PlotRangePadding area.
* Only None and Automatic are supported for GridLines,
FrameTicks and Ticks which means this example does
not support *Log*Plot.
uGraphicsDecorations[g_,
o : OptionsPattern[{
AspectRatio -> Automatic,(*Ignored*)
Axes -> False,
AxesOrigin -> {0, 0},
CoordinatesToolOptions -> {},(*Not supported*)
GridLines -> None,
Frame -> False,
FrameTicks -> None,
Method -> Null,(*Not supported*)
PlotRange -> {{-1, 1}, {-1, 1}},
PlotRangeClipping -> False,(*Not supported*)
PlotRangePadding -> Scaled[0.02],
Ticks -> None}]] :=
Block[{pr, dpr, prp, ao, ur, fd, fdlh, fdth, fdlv, fdtv, tm, drawAxes, axes,
drawTicks, tickMarks, gcdh, ndh, nfh, gcdv, ndv, nfv, tickMarkLabels,
drawFrame, drawGridLines, gridLines, frame, drawFrameTicks,
frameTickMarks, frameTickMarkLabels},
uGraphicsDecorations::unsupported =
"The option setting `1` is not supported.";
If[Length[#] != 0,
Message[uGraphicsDecorations::unsupported,
StringReplace[ToString[#], "#1" -> "#"]]] &[
FilterRules[{o}, #]] & /@ {CoordinatesToolOptions, Method};
(*If[OptionValue[PlotRangeClipping]=!=False,Message[
uGraphicsDecorations::unsupported,ToString[FilterRules[{o},
PlotRangeClipping]]]];
Print[o];*)
pr = OptionValue[PlotRange];
dpr = Subtract @@ Reverse@Transpose@pr;
prp = OptionValue[PlotRangePadding];
If[Head[prp] =!= List, prp = {{prp, prp}, {prp, prp}},
If[Head[prp[[1]]] =!= List, prp[[1]] = {prp[[1]], prp[[1]]}];
If[Head[prp[[2]]] =!= List, prp[[2]] = {prp[[2]], prp[[2]]}]];
pr += {{-If[Head[prp[[1, 1]]] =!= Scaled, prp[[1, 1]],
prp[[1, 1, 1]]*dpr[[1]]],
If[Head[prp[[1, 2]]] =!= Scaled, prp[[1, 2]],
prp[[1, 2, 1]]*dpr[[1]]]}, {-If[Head[prp[[2, 1]]] =!= Scaled,
prp[[2, 1]], prp[[2, 1, 1]]*dpr[[2]]],
If[Head[prp[[2, 2]]] =!= Scaled, prp[[2, 2]], prp[[2, 2, 1]]*dpr[[2]]]}};
ao = OptionValue[AxesOrigin];
ur[r_Rational] := N[r];
ur[r_Integer] := r;
ur[r_Real] := r;
drawAxes = OptionValue[Axes];
If[Head[drawAxes] == Symbol, drawAxes = {drawAxes, drawAxes}];
axes = If[Or @@ drawAxes, {#, Line @@ #2} & @@ Reap[
If[drawAxes[[1]], Sow[{{pr[[1, 1]], ao[[2]]}, {pr[[1, 2]], ao[[2]]}}]];
If[drawAxes[[2]], Sow[{{ao[[1]], pr[[2, 1]]}, {ao[[1]], pr[[2, 2]]}}]];
Directive[Antialiasing -> False]]];
fd = Function[{r, n},
Select[FindDivisions[r, n], LessEqual @@ Riffle[r, #] &]];
fdlh = fd[pr[[1]], 7];
fdth = Complement[fd[pr[[1]], 30], fdlh];
fdlv = fd[pr[[2]], 7];
fdtv = Complement[fd[pr[[2]], 30], fdlv];
tm = Function[{pt, d}, {ur /@ pt, Offset[d, ur /@ pt]}];
drawTicks = OptionValue[Ticks];
If[Or @@ drawAxes && Length[FilterRules[{o}, Ticks]] == 0,
drawTicks = Automatic];
If[Head[drawTicks] == Symbol, drawTicks = {drawTicks, drawTicks}];
tickMarks = If[drawTicks =!= {None, None},
{#, Line@Flatten[#2, 2]} & @@ Reap[
If[drawTicks[[1]] =!= None,
Sow[tm[{ao[[1]], #}, {4, 0}] & /@ fdlv];
Sow[tm[{ao[[1]], #}, {2, 0}] & /@ fdtv]];
If[drawTicks[[2]] =!= None,
Sow[tm[{#, ao[[2]]}, {0, 4}] & /@ fdlh];
Sow[tm[{#, ao[[2]]}, {0, 2}] & /@ fdth]];
Directive[Antialiasing -> False]]];
gcdh = GCD @@ fdlh;
If[Denominator[gcdh] > 1, ndh = Length[#1] - #2 & @@ RealDigits[gcdh];
nfh[h_] := ToString[NumberForm[N@h, {Infinity, ndh}]],
nfh[ h_] := ToString[h]];
gcdv = GCD @@ fdlv;
If[Denominator[gcdv] > 1, ndv = Length[#1] - #2 & @@ RealDigits[gcdv];
nfv[v_] := ToString[NumberForm[N@v, {Infinity, ndv}]],
nfv[v_] := ToString[v]];
tickMarkLabels =
If[drawTicks =!= {None, None}, Reap[
If[drawTicks[[1]] =!= None,
Sow[
Text[nfv[#], Offset[{-3, 0}, ur /@ {ao[[1]], #}], {1, 0}] & /@
Complement[fdlv, {ao[[2]]}]]];
If[drawTicks[[2]] =!= None,
Sow[
Text[nfh[#], Offset[{0, -3}, ur /@ {#, ao[[2]]}], {0, 1}] & /@
Complement[fdlh, {ao[[1]]}]]];]];
(*GridLines*)
drawGridLines = OptionValue[GridLines];
If[Head[drawGridLines] == Symbol,
drawGridLines = {drawGridLines, drawGridLines}];
gridLines = If[drawGridLines =!= {None, None}, {#, Line @@ #2} & @@ Reap[
If[drawGridLines[[1]] =!= None,
Sow[{{pr[[1, 1]], #}, {pr[[1, 2]], #}}] & /@ fdlv];
If[drawGridLines[[2]] =!= None,
Sow[{{#, pr[[2, 1]]}, {#, pr[[2, 2]]}}] & /@ fdlh];
Directive[Antialiasing -> False]]];
(*Frame*)
drawFrame = OptionValue[Frame];
If[Head[drawFrame] =!= List,
drawFrame = {{drawFrame, drawFrame}, {drawFrame, drawFrame}},
If[Head[drawFrame[[1]]] =!= List,
drawFrame[[1]] = {drawFrame[[1]], drawFrame[[1]]}];
If[Head[drawFrame[[2]]] =!= List,
drawFrame[[2]] = {drawFrame[[2]], drawFrame[[2]]}]];
frame = If[Or @@ Flatten@drawFrame,
tickMarks = {};
tickMarkLabels = {};
{#, Line @@ #2} & @@ Reap[
If[drawFrame[[1, 1]],
Sow[{{pr[[1, 1]], pr[[2, 1]]}, {pr[[1, 1]], pr[[2, 2]]}}]];
If[drawFrame[[1, 2]],
Sow[{{pr[[1, 2]], pr[[2, 1]]}, {pr[[1, 2]], pr[[2, 2]]}}]];
If[drawFrame[[2, 1]],
Sow[{{pr[[1, 1]], pr[[2, 1]]}, {pr[[1, 2]], pr[[2, 1]]}}]];
If[drawFrame[[2, 2]],
Sow[{{pr[[1, 1]], pr[[2, 2]]}, {pr[[1, 2]], pr[[2, 2]]}}]];
Directive[Antialiasing -> False]]];
drawFrameTicks = OptionValue[FrameTicks];
If[Or @@ Flatten@drawFrame && Length[FilterRules[{o}, FrameTicks]] == 0,
drawFrameTicks = Automatic];
If[Head[drawFrameTicks] =!= List,
drawFrameTicks = {{drawFrameTicks, drawFrameTicks}, {drawFrameTicks,
drawFrameTicks}},
If[Head[drawFrameTicks[[1]]] =!= List,
drawFrameTicks[[1]] = {drawFrameTicks[[1]], drawFrameTicks[[1]]}];
If[Head[drawFrameTicks[[2]]] =!= List,
drawFrameTicks[[2]] = {drawFrameTicks[[2]], drawFrameTicks[[2]]}]];
frameTickMarks = If[drawFrameTicks =!= {{None, None}, {None, None}},
{#, Line@Flatten[#2, 2]} & @@ Reap[
If[drawFrameTicks[[1, 1]] =!= None,
Sow[tm[{pr[[1, 1]], #}, {4, 0}] & /@ fdlv];
Sow[tm[{pr[[1, 1]], #}, {2, 0}] & /@ fdtv]];
If[drawFrameTicks[[1, 2]] =!= None,
Sow[tm[{pr[[1, 2]], #}, {-4, 0}] & /@ fdlv];
Sow[tm[{pr[[1, 2]], #}, {-2, 0}] & /@ fdtv]];
If[drawFrameTicks[[2, 1]] =!= None,
Sow[tm[{#, pr[[2, 1]]}, {0, 4}] & /@ fdlh];
Sow[tm[{#, pr[[2, 1]]}, {0, 2}] & /@ fdth]];
If[drawFrameTicks[[2, 2]] =!= None,
Sow[tm[{#, pr[[2, 2]]}, {0, -4}] & /@ fdlh];
Sow[tm[{#, pr[[2, 2]]}, {0, -2}] & /@ fdth]];
Directive[Antialiasing -> False]]];
frameTickMarkLabels =
If[drawFrameTicks =!= {{None, None}, {None, None}}, Reap[
If[drawFrameTicks[[1, 1]] =!= None,
Sow[
Text[nfv[#], Offset[{-3, 0}, ur /@ {pr[[1, 1]], #}], {1, 0}] & /@
fdlv]];
If[drawFrameTicks[[1, 2]] =!= None,
Sow[
Text[nfv[#], Offset[{3, 0}, ur /@ {pr[[1, 2]], #}], {-1, 0}] & /@
fdlv]];
If[drawFrameTicks[[2, 1]] =!= None,
Sow[
Text[nfh[#], Offset[{0, -3}, ur /@ {#, pr[[2, 1]]}], {0, 1}] & /@
fdlh]];
If[drawFrameTicks[[2, 2]] =!= None,
Sow[
Text[nfh[#], Offset[{0, 3}, ur /@ {#, pr[[2, 2]]}], {0, -1}] & /@
fdlh]];
]];
{g, axes, gridLines, tickMarks, tickMarkLabels, frame, frameTickMarks,
frameTickMarkLabels}
];
"Gregory Lypny" <gregory.lypny@videotron.ca> wrote in message
news:k0d4b9$m8b$1@smc.vnet.net...
> Hello everyone,
>
> Say I have two plots, y=x^2 and y=2x, aligned vertically using
GraphicsColumn. Their domains are aligned because x runs from -3 to +3 in
both. I'd like to be able to draw a line from a point in the top graph to a
point in the bottom graph. How can I do that?
>
> Regards,
>
> Gregory
>
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web