Prev: Relation Problem in Mathematica
Next: Import html
From: Armand Tamzarian on 17 Mar 2010 06:05 On Mar 16, 4:47 am, "Nasser M. Abbasi" <n...(a)12000.org> wrote: > Version 7: > > Many times I find I need to change the Plot Ticks (mostly to make the ticks > display in units of Pi for example instead of just in pure real numbers). > > The only way I know how to do this now is this: > > I build my own Ticks lists, and then do > > Plot[...,Ticks->{myXticks,myYTicks},....] > > But the problem with this, is tha I have to guess (Actually I do little more > than guessing) to obtain a good number of ticks to use, else I get too few > ticks or too many. > > But what would be better is to use the Ticks Mathematica uses on the plot > before I change the ticks myself. The reason is that I would know the most > optimal number of ticks to use. > > So, now What I want to do is this: First plot, but do not display, using > default Mathematica ticks. Then use AbsoluteOptions to get the ticks > information, then pull out the x-ticks list and the y-ticks from these, > modify each tick value to the value I want using my own transformation, then > set the plot again but now using the changed x and y ticks, then plot and > display. > > But I am stuck after getting the ticks information from the current plot. As > I am not able to figure how to pull out the x-ticks and y-ticks out of it. I > do not know how these are encoded in there. Here is what I do > > p = Plot[Sin[x], {x, 0, 10}, Ticks -> Automatic] > t = Ticks /. AbsoluteOptions[p] > > You can see from the plot, that x-ticks are {2,4,6,8,10} and y-ticks are > {-1.0,0,.5,1} > > But I do not know how to pull these 2 lists out of the "t" variable above. I > just need the list of numbers (do not care about the other attributes such > as Thickness and GrayLevel and all that.) > > Dimensions[t] > {2} > > Dimensions[t[[1]]] > {21, 4} > > Dimensions[t[[2]]] > {41, 4} > > Are these things documented somewhere? Looking at FullForm[t] was not much > help. > > thanks, > --Nasser This will change tick lengths newTicksLengths[image_Graphics, majorLength_Real, minorLength_Real] :=Module[{ticks}, ticks = AbsoluteOptions[image, Ticks]; ticks = ticks /. {a_?NumericQ, b_, {x_, 0.}, c : {_GrayLevel, _AbsoluteThickness}} :> {a, b, {Which[x == 0.00625, majorLength, x == = 0.00375, minorLength], 0.}, c}; Show[image, ticks] ] newTicks[p, 0.05, 0.025] Although this was something I already had for changing tick lengths, you should be able to modify it to change tick labels or other tick parameters. Mike
|
Pages: 1 Prev: Relation Problem in Mathematica Next: Import html |