From: Warren W. <war...@en...> - 2011-08-19 15:52:39
|
On Fri, Aug 19, 2011 at 3:12 AM, André Dankert <and...@go... > wrote: > Hi, > > I have a minor style problem, but, nevertheless, I can't solve it with > googles help. I want to have a minimum precision displayed on my ticks, i.e. > if the ticks are -1,-0.5,0,0.5,1 it should be displayed this way instead of > -1.0,-0.5,0.0,0.5,1.0. With the tick formatter I can set the tick > precission, but only for the whole axis (if I set %d for the example, it > will be -1,0,0,0,1). Also I use MaxNLocator, so I don't predefine the ticks > (I thought it's more convinient to use this already done procedure instead > of writing my own), so I'm more flexible, for example when I zoom in, but > therefore I don't even know, which the maximum precision is. > > Possible solutions would be: > 1. There is a number precision definition (something like %x.xf) which > produces numbers with minimum precision (again -1.0000 becomes -1 and > 2.47300 becomes 2.473) > Depending on the range of your values, "%g" might do want you want. E.g.: ----- from numpy import linspace, sin, pi from matplotlib.pyplot import plot, show, gca from matplotlib.ticker import FormatStrFormatter majorFormatter = FormatStrFormatter('%g') t = linspace(-1.0, 1.0, 41) s = sin(2*pi*t) plot(t,s) ax = gca() ax.xaxis.set_major_formatter(majorFormatter) show() ----- Warren > 2. Extract by MaxNLocator defined ticks, edit them accordingly and reassign > them (which would be still a lot of work) > > I even checked for solutions in Latex (because I use Latex string coding), > but this is even more inflexible, when it comes to numbers. But maybe > someone knows anything. > > Thanks! > > Best regards, > André > > > ------------------------------------------------------------------------------ > Get a FREE DOWNLOAD! and learn more about uberSVN rich system, > user administration capabilities and model configuration. Take > the hassle out of deploying and managing Subversion and the > tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2 > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > |