|
From: Massimo Di S. <mas...@gm...> - 2011-02-05 00:14:19
|
Hello All, i'm plotting a 3d colored surface using a 4D array that comes from a .mat file using this code : import scipy.io as sio import pylab as p import mpl_toolkits.mplot3d.axes3d as p3 def loadmatfile(matfile): matdata = sio.loadmat(matfile) return matdata def plot3dcolor(matfile): data = loadmatfile(matfile) x = data['X_depth'] y = data['Y_depth'] z = -data['Z_depth'] c = data['Z_compl'] fig=p.figure() ax = p3.Axes3D(fig) cmap = p.get_cmap('jet') norm = p.Normalize(c.min(), c.max()) colors = cmap(norm(c)) ax.plot_surface(x, y, z, rstride=10, cstride=10, facecolors=colors) ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') print x,y p.show() matfile = '/Users/epy/Desktop/complexity_depth_grid1.mat' plot3dcolor(matfile) the results is nice : http://img831.imageshack.us/f/schermata20110204a14542.png/ but as you can see, the mouse cursor shows me the x,y values (they are longitude and latitude) but on the axis i have them starting from 0 ... how can i change the axis to display the lon-lat coordinates ? thanks a lot for any help! Massimo. |
|
From: Benjamin R. <ben...@ou...> - 2011-02-05 00:41:23
|
On Friday, February 4, 2011, Massimo Di Stefano <mas...@gm...> wrote: > Hello All, > > > i'm plotting a 3d colored surface using a 4D array that comes from a .mat file > using this code : > > > import scipy.io as sio > import pylab as p > import mpl_toolkits.mplot3d.axes3d as p3 > > def loadmatfile(matfile): > matdata = sio.loadmat(matfile) > return matdata > > > def plot3dcolor(matfile): > data = loadmatfile(matfile) > x = data['X_depth'] > y = data['Y_depth'] > z = -data['Z_depth'] > c = data['Z_compl'] > fig=p.figure() > ax = p3.Axes3D(fig) > cmap = p.get_cmap('jet') > norm = p.Normalize(c.min(), c.max()) > colors = cmap(norm(c)) > ax.plot_surface(x, y, z, rstride=10, cstride=10, facecolors=colors) > ax.set_xlabel('X') > ax.set_ylabel('Y') > ax.set_zlabel('Z') > print x,y > p.show() > > > matfile = '/Users/epy/Desktop/complexity_depth_grid1.mat' > plot3dcolor(matfile) > > > > the results is nice : > > http://img831.imageshack.us/f/schermata20110204a14542.png/ > > > but as you can see, the mouse cursor shows me the x,y values (they are longitude and latitude) > but on the axis i have them starting from 0 ... > > how can i change the axis to display the lon-lat coordinates ? > > > thanks a lot for any help! > > Massimo. > > I suspect what is happening is that the axes label numbers are right, but is not showing the offset information. The display of offset data in a 3d plot is a new feature that exists only in the development branch. To confirm this, could you send me your may file (if it is small) so that I can try out your script? Ben Root |
|
From: Benjamin R. <ben...@ou...> - 2011-02-05 18:43:45
|
On Fri, Feb 4, 2011 at 6:41 PM, Benjamin Root <ben...@ou...> wrote: > On Friday, February 4, 2011, Massimo Di Stefano > <mas...@gm...> wrote: > > Hello All, > > > > > > i'm plotting a 3d colored surface using a 4D array that comes from a .mat > file > > using this code : > > > > > > import scipy.io as sio > > import pylab as p > > import mpl_toolkits.mplot3d.axes3d as p3 > > > > def loadmatfile(matfile): > > matdata = sio.loadmat(matfile) > > return matdata > > > > > > def plot3dcolor(matfile): > > data = loadmatfile(matfile) > > x = data['X_depth'] > > y = data['Y_depth'] > > z = -data['Z_depth'] > > c = data['Z_compl'] > > fig=p.figure() > > ax = p3.Axes3D(fig) > > cmap = p.get_cmap('jet') > > norm = p.Normalize(c.min(), c.max()) > > colors = cmap(norm(c)) > > ax.plot_surface(x, y, z, rstride=10, cstride=10, facecolors=colors) > > ax.set_xlabel('X') > > ax.set_ylabel('Y') > > ax.set_zlabel('Z') > > print x,y > > p.show() > > > > > > matfile = '/Users/epy/Desktop/complexity_depth_grid1.mat' > > plot3dcolor(matfile) > > > > > > > > the results is nice : > > > > http://img831.imageshack.us/f/schermata20110204a14542.png/ > > > > > > but as you can see, the mouse cursor shows me the x,y values (they are > longitude and latitude) > > but on the axis i have them starting from 0 ... > > > > how can i change the axis to display the lon-lat coordinates ? > > > > > > thanks a lot for any help! > > > > Massimo. > > > > > > I suspect what is happening is that the axes label numbers are right, > but is not showing the offset information. The display of offset data > in a 3d plot is a new feature that exists only in the development > branch. > > To confirm this, could you send me your may file (if it is small) so > that I can try out your script? > > Ben Root > Ok, so I can confirm that there are offset labels displaying when using the development version of mpl, which means that for some reason, the auto-ticker is deciding to use the offset display instead of just the regular display. Usually, this behavior doesn't trigger until 1e4 or larger, I believe? I will have to take a peek at what ticker is being used by default and seeing if it is different from the regular plots. In the meantime, if you need something to work right away, and you feel ambitious, you can fiddle with the tickers through the ax.w_xaxis and ax.w_yaxis objects (not the ax.xaxis and ax.yaxis objects): http://matplotlib.sourceforge.net/api/ticker_api.html?highlight=ticker#matplotlib-ticker Ben Root |
|
From: Massimo Di S. <mas...@gm...> - 2011-02-08 14:28:06
|
Hi Benjamin, have you reied the mat file ? i treid using a simple python array in a 2d plot and i'm having the same behavioure the x,y coordinates are displayed ok when the mouse roll over the graph but they are wrong in the axis labels. Il giorno 05/feb/2011, alle ore 09.23, Massimo Di Stefano ha scritto: > Hi Benjamin, > > The mat file is : > > <complexity_depth_grid1.mat> > > few kbyte :-) > > > thnaks! > > Massimo > > > > Il giorno 04/feb/2011, alle ore 19.41, Benjamin Root ha scritto: > >> On Friday, February 4, 2011, Massimo Di Stefano >> <mas...@gm...> wrote: >>> Hello All, >>> >>> >>> i'm plotting a 3d colored surface using a 4D array that comes from a .mat file >>> using this code : >>> >>> >>> import scipy.io as sio >>> import pylab as p >>> import mpl_toolkits.mplot3d.axes3d as p3 >>> >>> def loadmatfile(matfile): >>> matdata = sio.loadmat(matfile) >>> return matdata >>> >>> >>> def plot3dcolor(matfile): >>> data = loadmatfile(matfile) >>> x = data['X_depth'] >>> y = data['Y_depth'] >>> z = -data['Z_depth'] >>> c = data['Z_compl'] >>> fig=p.figure() >>> ax = p3.Axes3D(fig) >>> cmap = p.get_cmap('jet') >>> norm = p.Normalize(c.min(), c.max()) >>> colors = cmap(norm(c)) >>> ax.plot_surface(x, y, z, rstride=10, cstride=10, facecolors=colors) >>> ax.set_xlabel('X') >>> ax.set_ylabel('Y') >>> ax.set_zlabel('Z') >>> print x,y >>> p.show() >>> >>> >>> matfile = '/Users/epy/Desktop/complexity_depth_grid1.mat' >>> plot3dcolor(matfile) >>> >>> >>> >>> the results is nice : >>> >>> http://img831.imageshack.us/f/schermata20110204a14542.png/ >>> >>> >>> but as you can see, the mouse cursor shows me the x,y values (they are longitude and latitude) >>> but on the axis i have them starting from 0 ... >>> >>> how can i change the axis to display the lon-lat coordinates ? >>> >>> >>> thanks a lot for any help! >>> >>> Massimo. >>> >>> >> >> I suspect what is happening is that the axes label numbers are right, >> but is not showing the offset information. The display of offset data >> in a 3d plot is a new feature that exists only in the development >> branch. >> >> To confirm this, could you send me your may file (if it is small) so >> that I can try out your script? >> >> Ben Root > |
|
From: Benjamin R. <ben...@ou...> - 2011-02-08 15:47:51
|
On Tue, Feb 8, 2011 at 8:27 AM, Massimo Di Stefano <mas...@gm... > wrote: > Hi Benjamin, > > have you reied the mat file ? > > i treid using a simple python array in a 2d plot and i'm having the same > behavioure > the x,y coordinates are displayed ok when the mouse roll over the graph > but they are wrong in the axis labels. > > > Massimo, Perhaps you missed my previous email, so I will explain what I have found so far. First, in the 3d plots, the axes labels appear "wrong" because the offset label is missing. Offset labeling for 3d plots is a new feature that hasn't been released yet. However, if you do a pcolor() of the data on a 2D plot, you will see similar axes labels, but with the addition of the offset labels (the -7.025e1 and +4.259e1 in the attached plot). This means that all the labels should have that offset added to it to get the actual axis value. This is a way to save space. The reason for the offset labels to occur in the first place is that the range of axis values is so small, that it would take too much space to label each tick to the appropriate precision. Therefore, in order to display your plot sufficiently, you will need to take control of the tickers and the tick formatters. The API documentation can be found here: http://matplotlib.sourceforge.net/api/ticker_api.html There are a couple of examples of how to use tickers here: http://matplotlib.sourceforge.net/examples/pylab_examples/custom_ticker1.html http://matplotlib.sourceforge.net/examples/pylab_examples/centered_ticklabels.html There are others, but that's what I noticed from a quick look at http://matplotlib.sourceforge.net/examples/index.html I hope this helps! Ben Root |