## [Matplotlib-users] LinearLocator and digit precision

 [Matplotlib-users] LinearLocator and digit precision From: Nicolas Girard - 2005-09-10 21:56:03 Hi again, this is my second question related to the figure located at: http://nicolasgirard.nerim.net/img/artifacts.png The figure was generated using an instance of the following RunContour clas= s: class RunFigure: """ Une figure relative =E0 un unique run """ def __init__(self,run): """ On sp=E9cifie le run, soit par son nombre nb, soit directement = """ self.run =3D run # pour fichier de sortie self.plotname=3D'fig' self.dpi=3D150 self.orientation=3D'portrait' self.figsize=3D(5,3) # Titre de la figure self.figtitle=3D"Run %04d - %s"%(self.run.nb,self.run.title) def plot(self): #gray() self.fig=3Dfigure(figsize=3Dself.figsize,dpi=3Dself.dpi) def filename(self): return '/home/ngirard/out/%04d_%s.png'%(self.run.nb,self.plotname) def save(self): gray() savefig(self.filename(), dpi=3Dself.dpi,orientation=3Dself.orientation) class RunContour(RunFigure): def __init__(self,run,vals=3D['y1'],max=3DNone,**kwargs): RunFigure.__init__(self,run,**kwargs) #self.max =3D max or self.run.iz # pour fichier de sortie self.plotname=3D'cont' self.orientation =3D 'landscape' self.figsize=3D(11,7) r =3D self.run self.vals =3D [r.y[0],r.y[2],r.y[4],r.y[6],r.p,r.q,r.omega] self.valnames =3D [r"\rho",r"v_z",r"B_z",r"I",r"P",r"Q",r"\Omega"] def plot(self): RunFigure.plot(self) nbvals =3D len(self.vals) plotLocations =3D ["1%d%d"%(nbvals,i+1) for i in range(nbvals)] titles =3D [r"$%s$"%n for n in self.valnames] first=3DTrue for val in self.vals: plotLocation =3D plotLocations.pop(0) if first: ax1=3Dsubplot(plotLocation) ax1.xaxis.set_major_locator(LinearLocator(numticks=3D3)) first=3DFalse else: ax =3Dsubplot(plotLocation,sharex=3Dax1,sharey=3Dax1) setp(ax.get_yticklabels(), visible=3DFalse) setp(ax.get_xticklabels(), visible=3DFalse) contourf(self.run.r,self.run.z,val,30) title(titles.pop(0),fontproperties=3Dsmall) cb =3D colorbar(orientation=3D'horizontal') cb.xaxis.set_major_locator(LinearLocator(numticks=3D3)) On to my question: Note that I specified a linear locator for the x axis of the 1st plot, and = for=20 the x axis of the colorbars using the same code: ooooooo.set_major_locator(LinearLocator(numticks=3D3)) However all colorbars ticks are formatted with a 2 digit precision whereas = the=20 ticks of the 1st fig. xaxis are formatted with a 3 digit precision.=20 Why this discrepancy ? PS: please don't hesitate to give me any advice to enhance the above code i= f=20 you wish ! Thanks in advance, Nicolas

 [Matplotlib-users] LinearLocator and digit precision From: Nicolas Girard - 2005-09-10 21:56:03 Hi again, this is my second question related to the figure located at: http://nicolasgirard.nerim.net/img/artifacts.png The figure was generated using an instance of the following RunContour clas= s: class RunFigure: """ Une figure relative =E0 un unique run """ def __init__(self,run): """ On sp=E9cifie le run, soit par son nombre nb, soit directement = """ self.run =3D run # pour fichier de sortie self.plotname=3D'fig' self.dpi=3D150 self.orientation=3D'portrait' self.figsize=3D(5,3) # Titre de la figure self.figtitle=3D"Run %04d - %s"%(self.run.nb,self.run.title) def plot(self): #gray() self.fig=3Dfigure(figsize=3Dself.figsize,dpi=3Dself.dpi) def filename(self): return '/home/ngirard/out/%04d_%s.png'%(self.run.nb,self.plotname) def save(self): gray() savefig(self.filename(), dpi=3Dself.dpi,orientation=3Dself.orientation) class RunContour(RunFigure): def __init__(self,run,vals=3D['y1'],max=3DNone,**kwargs): RunFigure.__init__(self,run,**kwargs) #self.max =3D max or self.run.iz # pour fichier de sortie self.plotname=3D'cont' self.orientation =3D 'landscape' self.figsize=3D(11,7) r =3D self.run self.vals =3D [r.y[0],r.y[2],r.y[4],r.y[6],r.p,r.q,r.omega] self.valnames =3D [r"\rho",r"v_z",r"B_z",r"I",r"P",r"Q",r"\Omega"] def plot(self): RunFigure.plot(self) nbvals =3D len(self.vals) plotLocations =3D ["1%d%d"%(nbvals,i+1) for i in range(nbvals)] titles =3D [r"$%s$"%n for n in self.valnames] first=3DTrue for val in self.vals: plotLocation =3D plotLocations.pop(0) if first: ax1=3Dsubplot(plotLocation) ax1.xaxis.set_major_locator(LinearLocator(numticks=3D3)) first=3DFalse else: ax =3Dsubplot(plotLocation,sharex=3Dax1,sharey=3Dax1) setp(ax.get_yticklabels(), visible=3DFalse) setp(ax.get_xticklabels(), visible=3DFalse) contourf(self.run.r,self.run.z,val,30) title(titles.pop(0),fontproperties=3Dsmall) cb =3D colorbar(orientation=3D'horizontal') cb.xaxis.set_major_locator(LinearLocator(numticks=3D3)) On to my question: Note that I specified a linear locator for the x axis of the 1st plot, and = for=20 the x axis of the colorbars using the same code: ooooooo.set_major_locator(LinearLocator(numticks=3D3)) However all colorbars ticks are formatted with a 2 digit precision whereas = the=20 ticks of the 1st fig. xaxis are formatted with a 3 digit precision.=20 Why this discrepancy ? PS: please don't hesitate to give me any advice to enhance the above code i= f=20 you wish ! Thanks in advance, Nicolas