From: Ryan N. <rya...@gm...> - 2009-12-04 19:50:01
|
Than you for your assistance with AxesGrid. Concerning the documentation, on this page: http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.htmit says: Name Default Description aspect True aspect of axes then a few lines below: "*aspect*By default (False), widths and heigths of axes in the grid are scaled independently. If True, they are scaled according to their data limits (similar to aspect parameter in mpl)." *Here is a more complete example of my code: *In the following code, x_grid and y_grid are are arrays created by meshgrid and represent time and water depth respectively. z_dim is a dictionary of one or more arrays of sensor readings corresponding to the depths and times in x_grid and y_grid. from matplotlib import pyplot from mpl_toolkits.axes_grid import AxesGrid nrows = len(z_dim) # Number of rows DAP_figure = pyplot.figure(1,(20,8)) pyplot.figtext(0.05,.5,"Depth (m)",rotation='vertical',verticalalignment='center') # Create a grid of axes with the AxesGrid helper class my_grid = AxesGrid(DAP_figure, 111, # Only one grid in this figure nrows_ncols = (nrows,1), # one or more rows, but only one column axes_pad = 0.0, #pad between axes in inches aspect=False, # If True, all plots are superimposed upon one another. add_all=True, # not sure why this would ever be False share_all=True, # I think this means that all axes have the same x & y scales label_mode = "L", # labels for depth on left and time on bottom cbar_location="right", cbar_mode="each", # each axes has a different scale cbar_size="2%", cbar_pad="1%", ) for i,parameter in enumerate(z_dim): z_dim[parameter] = maskDAP(z_dim[parameter],parameter,dev_mult) #Need to mask NaNs and outliers for each grid ax = my_grid[i].pcolor(x_grid,y_grid,z_dim[parameter]) my_grid[i].set_ylabel(long_name[parameter]) # Puts a y label on every graph. my_grid.cbar_axes[i].colorbar(ax) my_grid.cbar_axes[i].axis["right"].toggle(ticklabels=True,label=True) my_grid.cbar_axes[i].set_ylabel(units[parameter]) #Puts the units on the right side of the colorbar pyplot.draw() pyplot.show() I do need a separate colorbar for each plot as they are results of different sensors all taken at the same time and depth scales. Here is what I have now: [image: wutSM.png] Which, aside from the extra scale labels on the x and y axis is getting close. Thank You for your help, -Ryan *matplotlib version:* On Thu, Dec 3, 2009 at 4:36 PM, Jae-Joon Lee <lee...@gm...> wrote: > > > On Thu, Dec 3, 2009 at 3:40 PM, Ryan Neve <rya...@gm...> wrote: > >> >> I tried all sorts of things, but finally, by setting aspect=False I got >> it to work. In the documentation, the table says this defaults to True and >> the explanation of aspect below says it defaults to False. Although I don't >> entirely understand what is going on, I think this threw me off. >> So then I had this: >> > > Can you be more specific about which documentation says the default aspect > is False? This may need to be fixed. Note that AxesGrid is designed > for displaying images with aspect=True. Otherwise, you may better stick to > the subplot.. > > > > >> [image: 84Kna.png] >> ... which looks much better, except that there are two sets of x and y >> axis labels? This seems to have something to do with the colorbar. I've got: >> >> > To me, there is another axes underneath the AxesGrid. It is hard to tell > without a complete code. > > > >> label_mode = "L", >> cbar_location="right", >> cbar_mode="each", >> cbar_size="2%", >> cbar_pad="0.5%" >> >> Now I'm trying to get scales and labels on my colorbars. >> I tried: >> for i,parameter in enumerate(z_dim): >> ax = my_grid[i].pcolor(x_grid,y_grid,z_dim[parameter]) # This is the >> pcolor plot >> my_grid[i].set_ylabel('Depth') # Correctly puts a y label on every >> plot. >> cb = my_grid.cbar_axes[i].colorbar(ax) # Puts in a colorbar for this >> axes?s >> cb.set_ylabel(parameter) #It would be nice if this was on the far >> right next to the colorbar. I don't see it anywhere. Perhaps underneath >> something? > > > The label of the colorbar is set to invisible by default (this is a bug). > So, try something like > > my_grid.cbar_axes[i].set_ylabel(parameter) > my_grid.cbar_axes[i].axis["right"].toggle(ticklabels=True, > label=True) > > > > >> >> [image: DPkWz.png] >> It looks like perhaps the colorbar axes is inside the ax axes rather than >> besides it? >> In the demo_grid_with_each_cbar<http://matplotlib.sourceforge.net/examples/axes_grid/demo_axes_grid.html>example, how would you put a scale and label on the colorbar like in this >> plot:? >> [image: 58dFK.png] >> I can put a y_label on each contour plot, but since they all have depth, >> I'd like to label this only once. >> Is there a way to label the entire AxesGrid (or is that subplot?)? >> >> > Does label_mode="1" do what you want? > You may manually make some of the labels invisible. > > Please post a "complete", but simple, script that reproduces your problem. > Otherwise, it is hard to track down what is wrong. > Also, please report what version of matplotlib you're using. The axes_grid > toolkit is relatively new and some of the feature may not work in older > versions. > > Regards, > > -JJ > > > >> Thank you very much for your help, >> >> -Ryan >> >> >> >> On Wed, Dec 2, 2009 at 10:21 PM, Jae-Joon Lee <lee...@gm...>wrote: >> >>> This happens because, when the AxesGrid is created, gca() is set to the >>> last axes, which is the last colobar axes. >>> >>> If you use axes_grid toolkit, you'd better not use pyplot command that >>> works on axes. Instead, use axes method directly. >>> >>> For example, instead of "pyplot.pcolor(..)" , use "ax.pcolor(..)". >>> >>> Regards, >>> >>> -JJ >>> >>> >>> >>> >>> On Wed, Dec 2, 2009 at 2:18 PM, Ryan Neve <rya...@gm...> wrote: >>> >>>> Hello, >>>> >>>> I'm trying to use AxesGrid but I'm running into a problem: >>>> I can plot a single pcolor plot: >>>> [image: 58dFK.png] >>>> But when I try to use AxesGrid, my pcolor plot is ending up where I >>>> expect my colorbar to be. >>>> [image: mEbTA.png] >>>> >>>> I want to have up to 6 of these plots stacked vertically, sharing a >>>> common time axis and y (depth) scale. >>>> >>>> I'll try to simplify my code to show what I'm doing: >>>> >>>> # I have arrays x_grid and y_grid for time and water depth. >>>> # z_dim is a dictionary of arrays (one for each plot) >>>> # In the plot above it has two arrays. >>>> from matplotlib import pyplot >>>> nrows = len(z_dim) # Number of rows is the number of arrays >>>> My_figure = pyplot.figure(1,(8,8)) >>>> my_grid = AxesGrid(My_figure, 111, #Is this always 111? >>>> nrows_ncols = (nrows,1), # Always one column >>>> axes_pad = 0.1, >>>> add_all=True, >>>> share_all=True, # They all share the same time and depth >>>> scales >>>> label_mode = "L", >>>> cbar_location="right", >>>> cbar_mode="each", >>>> cbar_size="7%", >>>> cbar_pad="2%", >>>> ) >>>> for row_no,parameter in enumerate(z_dim): >>>> ax = my_grid[row_no] >>>> ax = pyplot.pcolor(x_grid,y_grid,z_dim[parameter]) >>>> pyplot.draw() >>>> pyplot.show() >>>> >>>> I eventually want to end up with something like this matlab output >>>> (which I didn't generate): >>>> [image: jiIaK.png] >>>> but without the duplication of x scales. >>>> >>>> I'm new to pyplot and even after reading the documentation much of this >>>> is baffling. >>>> >>>> -Ryan >>>> >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> Join us December 9, 2009 for the Red Hat Virtual Experience, >>>> a free event focused on virtualization and cloud computing. >>>> Attend in-depth sessions from your desk. Your couch. Anywhere. >>>> http://p.sf.net/sfu/redhat-sfdev2dev >>>> _______________________________________________ >>>> Matplotlib-users mailing list >>>> Mat...@li... >>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >>>> >>>> >>> >> > |