From: Nasser M. Abbasi on 25 Mar 2010 05:28 background: When plotting, one can supply a specific tick function, which is automatically called by the Plot code. This allows one to have control on how the ticks are set. This is useful. Here is an example: ------------------------------ ticksX[min_, max_] := Table[{i, Style[i, Red, 12], {0.04, 0}}, {i, Ceiling[min], Floor[max]}] Plot[Sin[x], {x, 0, 4}, Ticks -> {ticksX, Automatic}] ------------------------------- The only problem with the above design, is that sometimes one might want to have additional information inside the ticks function, other than just the min and the max ticks values, to help it decide what to do. Assume this additional information is some variable, say T. Right now, the only way to access this variable from inside the ticks function, is to have T be global. I prefer not to use global variables/symbols. It would be much better if Ticks would take additional, and optional parameter, to pass to the ticks function. May be something like ------------------------------------ ticksX[min_, max_,extra_List] := If[ extra[[1]]==.... etc.....] Plot[Sin[x], {x, 0, 4}, Ticks -> {ticksX[{T}], Automatic}] --------------------------------------- And now inside my ticks function, I can access the additional information if I want to use it to help me set the ticks. If the above is not possible in version 7, is it possible to make this enhancement available in version 8? --Nasser
From: Carl K. Woll on 26 Mar 2010 06:34 On 3/25/2010 11:20 AM, Nasser M. Abbasi wrote: > > ----- Original Message ----- From: "Carl K. Woll" <carlw(a)wolfram.com> > To: "Nasser M. Abbasi" <nma(a)12000.org> > Cc: <mathgroup(a)smc.vnet.net> > Sent: Thursday, March 25, 2010 4:46 AM > Subject: Re: How to pass additional parameters to the ticks > function? > > >> On 3/25/2010 5:28 AM, Nasser M. Abbasi wrote: >>> background: >>> >>> When plotting, one can supply a specific tick function, which is >>> automatically called by the Plot code. This allows one to have >>> control on >>> how the ticks are set. >>> >>> This is useful. Here is an example: >>> >>> ------------------------------ >>> ticksX[min_, max_] := Table[{i, Style[i, Red, 12], {0.04, 0}}, >>> {i, Ceiling[min], Floor[max]}] >>> >>> Plot[Sin[x], {x, 0, 4}, Ticks -> {ticksX, Automatic}] >>> ------------------------------- >>> >>> The only problem with the above design, is that sometimes one might >>> want to >>> have additional information inside the ticks function, other than >>> just the >>> min and the max ticks values, to help it decide what to do. >>> >>> Assume this additional information is some variable, say T. >>> >>> Right now, the only way to access this variable from inside the ticks >>> function, is to have T be global. I prefer not to use global >>> variables/symbols. >>> >>> It would be much better if Ticks would take additional, and optional >>> parameter, to pass to the ticks function. >>> >>> May be something like >>> >>> ------------------------------------ >>> ticksX[min_, max_,extra_List] := If[ extra[[1]]==.... etc.....] >>> >>> >>> Plot[Sin[x], {x, 0, 4}, Ticks -> {ticksX[{T}], Automatic}] >>> --------------------------------------- >>> >>> And now inside my ticks function, I can access the additional >>> information if >>> I want to use it to help me set the ticks. >>> >>> If the above is not possible in version 7, is it possible to make this >>> enhancement available in version 8? >>> >>> --Nasser >>> >>> > > >> Why can't you do: >> >> ticksX[extra_][min_,max_] := If[... >> >> ? >> >> Carl Woll >> Wolfram Research > > > Thanks Carl. That worked! But how did you know that? When I looked at > the documenation for Ticks function, it only talks about min,max: > > "The tick mark function func[Subscript[x, min],Subscript[x, max]] may > return any other tick mark option." So, in this case your func is ticksX[extra], and as the above says, the graphics routine does ticksX[extra][min, max] to find out what the ticks should be. > > and all the examples, shows only min,max arguments. So I did not know > I can pass additional arguments (may be I should have tried). > > Or is this trick common in general? How does one know which function > then takes extra arguments like this or not? And why did you type it as > > ticksX[extra_][min_,max_] > > and not as > > ticksX[min_,max_,extra_] You could do: Ticks -> {ticksX[##, extra]&, Automatic} as well using your original definition of ticksX. Basically, if a tick spec is not a list (or Automatic), then the graphics routine will assume that the spec is a function and feed it min, max. Carl > > Is there an advantage of one over the other? > > --Nasser
From: Carl K. Woll on 26 Mar 2010 06:33 On 3/25/2010 5:28 AM, Nasser M. Abbasi wrote: > background: > > When plotting, one can supply a specific tick function, which is > automatically called by the Plot code. This allows one to have control on > how the ticks are set. > > This is useful. Here is an example: > > ------------------------------ > ticksX[min_, max_] := Table[{i, Style[i, Red, 12], {0.04, 0}}, > {i, Ceiling[min], Floor[max]}] > > Plot[Sin[x], {x, 0, 4}, Ticks -> {ticksX, Automatic}] > ------------------------------- > > The only problem with the above design, is that sometimes one might want to > have additional information inside the ticks function, other than just the > min and the max ticks values, to help it decide what to do. > > Assume this additional information is some variable, say T. > > Right now, the only way to access this variable from inside the ticks > function, is to have T be global. I prefer not to use global > variables/symbols. > > It would be much better if Ticks would take additional, and optional > parameter, to pass to the ticks function. > > May be something like > > ------------------------------------ > ticksX[min_, max_,extra_List] := If[ extra[[1]]==.... etc.....] > > > Plot[Sin[x], {x, 0, 4}, Ticks -> {ticksX[{T}], Automatic}] > --------------------------------------- > > And now inside my ticks function, I can access the additional information if > I want to use it to help me set the ticks. > > If the above is not possible in version 7, is it possible to make this > enhancement available in version 8? > > --Nasser > > Why can't you do: ticksX[extra_][min_,max_] := If[... ? Carl Woll Wolfram Research
From: Nasser M. Abbasi on 26 Mar 2010 06:34 ----- Original Message ----- From: "Carl K. Woll" <carlw(a)wolfram.com> To: "Nasser M. Abbasi" <nma(a)12000.org> Cc: <mathgroup(a)smc.vnet.net> Sent: Thursday, March 25, 2010 4:46 AM Subject: Re: How to pass additional parameters to the ticks function? > On 3/25/2010 5:28 AM, Nasser M. Abbasi wrote: >> background: >> >> When plotting, one can supply a specific tick function, which is >> automatically called by the Plot code. This allows one to have control on >> how the ticks are set. >> >> This is useful. Here is an example: >> >> ------------------------------ >> ticksX[min_, max_] := Table[{i, Style[i, Red, 12], {0.04, 0}}, >> {i, Ceiling[min], Floor[max]}] >> >> Plot[Sin[x], {x, 0, 4}, Ticks -> {ticksX, Automatic}] >> ------------------------------- >> >> The only problem with the above design, is that sometimes one might want >> to >> have additional information inside the ticks function, other than just >> the >> min and the max ticks values, to help it decide what to do. >> >> Assume this additional information is some variable, say T. >> >> Right now, the only way to access this variable from inside the ticks >> function, is to have T be global. I prefer not to use global >> variables/symbols. >> >> It would be much better if Ticks would take additional, and optional >> parameter, to pass to the ticks function. >> >> May be something like >> >> ------------------------------------ >> ticksX[min_, max_,extra_List] := If[ extra[[1]]==.... etc.....] >> >> >> Plot[Sin[x], {x, 0, 4}, Ticks -> {ticksX[{T}], Automatic}] >> --------------------------------------- >> >> And now inside my ticks function, I can access the additional information >> if >> I want to use it to help me set the ticks. >> >> If the above is not possible in version 7, is it possible to make this >> enhancement available in version 8? >> >> --Nasser >> >> > Why can't you do: > > ticksX[extra_][min_,max_] := If[... > > ? > > Carl Woll > Wolfram Research Thanks Carl. That worked! But how did you know that? When I looked at the documenation for Ticks function, it only talks about min,max: "The tick mark function func[Subscript[x, min],Subscript[x, max]] may return any other tick mark option." and all the examples, shows only min,max arguments. So I did not know I can pass additional arguments (may be I should have tried). Or is this trick common in general? How does one know which function then takes extra arguments like this or not? And why did you type it as ticksX[extra_][min_,max_] and not as ticksX[min_,max_,extra_] Is there an advantage of one over the other? --Nasser
From: David Park on 26 Mar 2010 06:34 Use SubValues. ticksX[parms__]:=Function[{min, max}, definitions...] David Park djmpark(a)comcast.net http://home.comcast.net/~djmpark/ From: Nasser M. Abbasi [mailto:nma(a)12000.org] background: When plotting, one can supply a specific tick function, which is automatically called by the Plot code. This allows one to have control on how the ticks are set. This is useful. Here is an example: ------------------------------ ticksX[min_, max_] := Table[{i, Style[i, Red, 12], {0.04, 0}}, {i, Ceiling[min], Floor[max]}] Plot[Sin[x], {x, 0, 4}, Ticks -> {ticksX, Automatic}] ------------------------------- The only problem with the above design, is that sometimes one might want to have additional information inside the ticks function, other than just the min and the max ticks values, to help it decide what to do. Assume this additional information is some variable, say T. Right now, the only way to access this variable from inside the ticks function, is to have T be global. I prefer not to use global variables/symbols. It would be much better if Ticks would take additional, and optional parameter, to pass to the ticks function. May be something like ------------------------------------ ticksX[min_, max_,extra_List] := If[ extra[[1]]==.... etc.....] Plot[Sin[x], {x, 0, 4}, Ticks -> {ticksX[{T}], Automatic}] --------------------------------------- And now inside my ticks function, I can access the additional information if I want to use it to help me set the ticks. If the above is not possible in version 7, is it possible to make this enhancement available in version 8? --Nasser
|
Next
|
Last
Pages: 1 2 Prev: counting number of variables in an expression Next: Convert to lower Mathematica version |