AxesGrid: X axis dates and other axis questions.

(sorry if this is a duplicate post)
Jae,

Thank you for your help. I found the problem. It was caused
by using pyplot.title(). It is working better now.
I next have to
figure out how to do the following within AxesGrid:

  1. How to convert the x axis labels from an integer
    value representing epoch seconds to a nicely formatted date. I think
    this has something to do with matplotlib.dates.DateFormatter. I hope that this will remove the 1.25325e9 from the plot.

  2. How to minimize or eliminate the white bands on the right and
    bottom of each axes caused by the axis scale exceeding the data values.

  3. How
    to eliminate (or hide) the first major tic label on the y axis (always 0) so it
    doesn’t overlap with the last tick from the previous y axis.
    It seems like there may be a different way to approach this than with subplot()
    Regards,
    -Ryan
    Here’s a complete example:

from matplotlib import pyplot

from mpl_toolkits.axes_grid import AxesGrid

from numpy import arange, linspace, meshgrid, random, transpose

Generate some data

x_dim = linspace(1253250000,1253250000 + 606024,47) # This is epoch seconds

y_dim = arange(0,-2.7,-0.1)
z_dim = {}

z_dim[‘chl’] = random.rand(len(x_dim),len(y_dim)) + linspace(5,26,len(y_dim))
z_dim[‘do’] = random.rand(len(x_dim),len(y_dim)) + linspace(5,10,len(y_dim))

z_dim[‘turb’] = random.rand(len(x_dim),len(y_dim)) + linspace(4.5,12.5,len(y_dim))
x_grid,y_grid = meshgrid(x_dim,y_dim)

x_grid = transpose(x_grid)
y_grid = transpose(y_grid)

Start the plotting routines

DAP_figure = pyplot.figure(1,(8,8))
#pyplot.title(‘Title goes here’) # THIS IS THE LINE THAT CAUSES THE EARLIER PROBLEM

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 DAP_figure

            nrows_ncols = (3,1),

            axes_pad = 0.0, #pad between axes in inches

aspect=False, #By default (False), widths and heigths of axes in the
grid are scaled independently. If True, they are scaled according to
their data limits

            add_all=True, # Add axes to figures if True (default True)

            share_all=False, # xaxis & yaxis of all axes are shared if True (default False)

label_mode = “L”, # location of tick labels thaw will be displayed. “1”
(only the lower left axes), “L” (left most and bottom most axes), or
“all”

            cbar_location="right", # "right" or "top"
            cbar_mode="each", # "None","single", or "each"

            cbar_size="2%",
            cbar_pad="1%",

            )

for i,parameter in enumerate(z_dim):

ax = my_grid[i].pcolor(x_grid,y_grid,z_dim[parameter])

my_grid[i].set_ylabel(parameter) # Puts a y label on every graph. Eventually we want this labeled only once.

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")
my_grid[i].axis["bottom"].major_ticklabels.set_rotation(45) #

pyplot.show()

···

On Tue, Dec 8, 2009 at 7:39 PM, Jae-Joon Lee <lee.j.joon@…287…> wrote:

Did you test the code in my previous post?

If you want to get some help, you need to take your time to create a simple and complete example (which reproduces the problem) that others can easily test.

Since I believe the problem is due to the existence of an extra axes, your example don’t need to show any images. Please post a simple script that draws a blank AxesGrid and shows extra ticklabels as your current code does.

Regards,

-JJ

While there are certain differences, most of the usual matplotlib command supposed to work. So, I recommend you to read the matplotlib documentation first.

  1. There are lots of examples in the gallery. Please take a look.

  2. see the code below.

  3. this kind of thing is difficult to do with axes_grid toolkit. but see below.

First, you need to change the x-values to date (not seconds).

Then, add the code below inside your for loop.

Other than ax.axis[“bottom”]… thing, these are just normal matplotlib command.

Also, I should have mentioned it earlier, but I don’t see any need of axes_grid toolkit in your code. You’d better simply use subplot, which is recommended if you’re not familiar with matplotlib.

Regards,

-JJ

ax = my_grid[i]

ax.autoscale_view(tight=True) # adjust xlim and ylim
# you can manually call ax.set_xlim and ax.set_ylim.

ax.xaxis_date() # tick format as date and time

ax.axis["bottom"].major_ticklabels.set_rotation(30)
ax.axis["bottom"].major_ticklabels.set_ha("right")
ax.axis["bottom"].major_ticklabels.set_va("top")

# with axes_grid toolkit, it is difficult to make a certain
# ticklabel invisible (without disabling the tick line).  The
# below line of code slightly adjust the ylim so that y=0 ticks
# are not shown

ax.set_ylim(ymax=-0.001)
···

On Fri, Dec 11, 2009 at 2:34 PM, Ryan Neve <ryan.neve@…120…287…> wrote:

Thank you for your help. I found the problem. It was caused
by using pyplot.title(). It is working better now.
I next have to
figure out how to do the following within AxesGrid:

  1. How to convert the x axis labels from an integer
    value representing epoch seconds to a nicely formatted date. I think
    this has something to do with matplotlib.dates.DateFormatter. I hope that this will remove the 1.25325e9 from the plot.

  2. How to minimize or eliminate the white bands on the right and
    bottom of each axes caused by the axis scale exceeding the data values.

  3. How
    to eliminate (or hide) the first major tic label on the y axis (always 0) so it
    doesn’t overlap with the last tick from the previous y axis.
    It seems like there may be a different way to approach this than with subplot()