MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Manipulate[] and ticks --- offset to avoid collision?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108802] Re: Manipulate[] and ticks --- offset to avoid collision?
  • From: telefunkenvf14 <rgorka at gmail.com>
  • Date: Thu, 1 Apr 2010 05:59:55 -0500 (EST)
  • References: <hov81e$92u$1@smc.vnet.net>

On Mar 31, 5:26 am, telefunkenvf14 <rgo... at gmail.com> wrote:
> Mathgroup:
>
> I am currently able to construct a manipulatable plot of a supply and
> demand diagram that includes custom tick marks, set to dynamically
> display the current equilibrium price and quantity.
>
> Question: Can someone explain how to add an additional set of custom
> tick marks that display 'lower' (on the x axis) and 'to the left' (on
> the y axis) of my 'main' tick marks, so I don't have tick-mark
> collisions?
>
> (FYI, the second set of tick marks would be linked to shifted copies
> of the original demand and supply curves. So far, the best workaround
> I've come up with is to use conditional statements, such as Which[] or
> nested If[], to switch the additional tick marks on or off based on
> proximity to my 'main' ticks.)
>
> Any help, or other creative ideas, would be greatly appreciated.
>
> -RG

Well, I played around and something like this works, but I'd still be
interested in suggestions for improvement. One idea I haven't yet
tried to implement: a Checkbox[ ] to show or hide sets of ticks. Could
someone help with that?

(*First, a couple of convenience functions called by the plotting
routine*)

inverseLinear[name_,priceVariable_,a_,b_,shift_]:=
    (
    priceVariable==(a+shift)+ b*name
    )

linearMarket[name_,priceVariable_,s0_,s1_,d0_,d1_,sShift_,dShift_]:=
	{
	name-> -((-d0-dShift+s0+sShift)/(-d1+s1)),
 	priceVariable-> -((-d1*s0+d0*s1+dShift*s1-d1*sShift)/(d1-s1))
	}

(*Here's my Plot[ ]*)

linearMarketPlot[name_,priceVariable_,s0_,s1_,d0_,d1_,sShift_,dShift_]:=
    Module[ {marketTitleName,sols1,sols2,eqY1,eqY2,eqP1,eqP2},
        marketTitleName =
MapAt[ToUpperCase[#1]&,Characters[ToString[name]],1]//StringJoin;
        sols1=linearMarket[name,priceVariable,s0,s1,d0,d1,0,0]//N;
        eqY1=sols1[[1,2]];
        eqP1=sols1[[2,2]];

sols2=linearMarket[name,priceVariable,s0,s1,d0,d1,sShift,dShift]//N;
        eqY2=sols2[[1,2]];
        eqP2=sols2[[2,2]];
        Plot[
        	{inverseLinear[name,priceVariable,s0,s1,sShift]
[[2]],inverseLinear[name,priceVariable,s0,s1,0][[2]],
        	inverseLinear[name,priceVariable,d0,d1,dShift]
[[2]],inverseLinear[name,priceVariable,d0,d1,0][[2]]},{name,0,d0*1.1},
            AxesOrigin->{0,0},
            PlotRange->{0,d0*1.2},
            PlotStyle-
>{Directive[Thick,Dashed,Darker[Blue]],Directive[Thick,Darker[Blue]],
            	Directive[Thick,Dashed,Purple],Directive[Thick,Purple]},
            PlotLabel->Style[marketTitleName<>" Market",FontFamily-
>"Calibri",Bold,14],
            AxesLabel->{name,priceVariable},
            Ticks->
            	{
                	{{eqY1,"\!\(\*SubscriptBox[\"q\", \"1\"]\)"<>" =
"<>ToString[NumberForm[eqY1,{10,2}]]},{eqY2,"\<\n\!\(\) \>
"<>ToString[NumberForm[eqY2,{10,2}]]}},
                	{{eqP1,"\!\(\*SubscriptBox[\"p\", \"1\"]\)"<>" =
"<>ToString[NumberForm[eqP1,{10,2}]]},{eqP2,ToString[NumberForm[eqP2,
{10,2}]]}}
                },
            TicksStyle->Directive[9,Thin],
            LabelStyle->{FontFamily->"Calibri",Bold,12},
            	Prolog->
                	{
                	{Thick,Lighter@Gray,Dotted,Line[{{eqY1,0},
{eqY1,eqP1}}]},
                	{Thick,Lighter@Gray,Dotted,Line[{{0,eqP1},
{eqY1,eqP1}}]},
                	{Thick,Gray,Dotted,Line[{{eqY2,0},{eqY2,eqP2}}]},
                	{Thick,Gray,Dotted,Line[{{0,eqP2},{eqY2,eqP2}}]}
                    },
                Epilog->
                	{
                	{PointSize[0.025],Point[{eqY2,eqP2}]},
                	{PointSize[0.025],Point[{eqY1,eqP1}]}
                    }
        ]
    ]

(*Here is an example Manipulate[ ]*)

DynamicModule[{sShift, dShift},
 Manipulate[linearMarketPlot[apples, p, 1, 1, 100, -1, sShift,
dShift],
  {{sShift, 0, "Supply Shift"}, -50, 50},
  {{dShift, 0, "Demand Shift"}, -50, 50},
  TrackedSymbols :> {sShift, dShift}
  ]
 ]


  • Prev by Date: Re: Managing packages in the workbench
  • Next by Date: Re: a little nasty problem?
  • Previous by thread: Re: Managing packages in the workbench
  • Next by thread: Context TimeSeries