How to extract the x-axis and y-axis current ticks of a plot from AbsoluteOptions?
- To: mathgroup at smc.vnet.net
- Subject: [mg108400] How to extract the x-axis and y-axis current ticks of a plot from AbsoluteOptions?
- From: "Nasser M. Abbasi" <nma at 12000.org>
- Date: Tue, 16 Mar 2010 04:47:06 -0500 (EST)
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