From: Pål G. E. <pa...@gm...> - 2013-07-08 08:08:31
|
Hi Thank you that solves the problem we had. I'm sorry for posting this on the development list, it was intended for the users list, and I somehow entered the wrong address. Regards Pål On 7 July 2013 21:44, Eric Firing <ef...@ha...> wrote: > On 2013/07/04 11:43 PM, Pål Gunnar Ellingsen wrote: > > Hi > > > > I'm having some problems with the formatter of ticks in a polar plot. > > Below is a minimum example > > The first figure is correct, the second has wrong ticks. > > > > This has be tested both on 1.2.0 and the latest from git (1.4.x, commit > > 64cc3416396ffb2811af80fc810ed63572df71d9 ) > > > > Does anyone know whys this happens? > > Is it a bug in MaxNLocator > > No, it is a misunderstanding of how the colorbar works. It's long axis > is using its own units, and it maps the color scale to those units. > Therefore, one should not try to manipulate the axis properties > directly. Below I show two altered lines and one deletion. I think > this will produce what you want. > > > > > Kind regards > > > > Pål > > > > --------------------------- > > #!/usr/bin/env python > > > > import numpy as np > > import matplotlib.pyplot as plt > > from matplotlib.ticker import MaxNLocator > > > > # Data > > M=np.sin(np.meshgrid(np.arange(30),np.arange(30))) > > M=np.squeeze(M[0,:,:]) > > Radius=np.arange(30) > > Theta=np.arange(30) > > > > # Plotting the correct figure > > print('Correct ticks') > > fig=plt.figure() > > ax1 = fig.add_axes([0,0,0.8,1],projection='polar') > > c = ax1.pcolormesh(Theta, Radius, M) > > ax1.set_frame_on(False) > > plt.xticks([]) > > plt.yticks([]) > > ax2=fig.add_axes([0.9,0.1,0.05,0.7]) > > cb=fig.colorbar(c,cax=ax2) > > plt.show() > > > > # Doing the same plot > > print('Wrong ticks by using formatter') > > fig=plt.figure() > > ax1 = fig.add_axes([0,0,0.8,1],projection='polar') > #> c = ax1.pcolormesh(Theta, Radius, M) > > c = ax1.pcolormesh(Theta, Radius, M, vmin=-1, vmax=1) > > > ax1.set_frame_on(False) > > plt.xticks([]) > > plt.yticks([]) > > ax2=fig.add_axes([0.9,0.1,0.05,0.7]) > #> cb=fig.colorbar(c,cax=ax2) > > cb = fig.colorbar(c, cax=ax2, ticks=MaxNLocator(3)) > > > > #> # except now setting a limit to the number of ticks using a formatter > #> # which results in wrong ticks > #> cb.ax.yaxis.set_major_locator(MaxNLocator(3)) > > > plt.show() > > Eric > > > ----------------------- > > > > > > > ------------------------------------------------------------------------------ > > This SF.net email is sponsored by Windows: > > > > Build for Windows Store. > > > > http://p.sf.net/sfu/windows-dev2dev > > > > > > > > _______________________________________________ > > Matplotlib-devel mailing list > > Mat...@li... > > https://lists.sourceforge.net/lists/listinfo/matplotlib-devel > > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Windows: > > Build for Windows Store. > > http://p.sf.net/sfu/windows-dev2dev > _______________________________________________ > Matplotlib-devel mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-devel > |