if (len(aperture_names) == len(aperture_values)):
  nb_apertures = len(aperture_names)
else:
  raise ValueError("aperture_values and aperture_names do not have the same length")

# We generate the values for the distances
delta_distance = (d_max - d_min) / float(nb_distance-1)
distances = np.array([d_min + i * delta_distance for i in range(nb_distance)])

#~ # We generate the values for the focal
#~ delta_focal = (focal_max - focal_min) / float(nb_focals-1)
#~ focals = np.array([focal_min + i * delta_focal for i in range(nb_focals)])

# We prepare the plot
fig = pl.figure(1)
nb_subplot = autiwa.get_subplot_shape(len(focals))

fig.subplots_adjust(left=0.12, bottom=0.1, right=0.96, top=0.95, wspace=0.26, hspace=0.26)

#~ myxfmt = ScalarFormatter(useOffset=True)
#~ myxfmt._set_offset(1e5)
#~ myxfmt.set_scientific(True)
#~ myxfmt.set_powerlimits((-3, 3)) 
myxfmt = FormatStrFormatter('%.0f')
myminorxfmt = FormatStrFormatter('%.1f')


# We generate a list of colors
colors = [ '#'+li for li in autiwa.colorList(len(dofs))]

for focal_length in focals:
phi[too_low] = phi[too_low] + 360.
phi[too_high] = phi[too_high] - 360.

delta_longitude = long_of_peri_outer - long_of_peri_inner
delta_longitude = delta_longitude%(360.)
too_low = delta_longitude < ANGLE_MIN
too_high = delta_longitude > ANGLE_MAX
delta_longitude[too_low] = delta_longitude[too_low] + 360.
delta_longitude[too_high] = delta_longitude[too_high] - 360.


# We chose the number of plot in x and y axis for the p.multi
# environment in order to plot ALL the resonant angles and have x and
# y numbers as close on from another as possible. There are q+1
# resonant angles, the period ratio and w1 - w2, i.e q+3 plots
(nb_lines, nb_rows) = autiwa.get_subplot_shape(q+3)

# on trace les plots
myxfmt = ScalarFormatter(useOffset=True)
myxfmt._set_offset(1e5)
myxfmt.set_scientific(True)
myxfmt.set_powerlimits((-3, 3)) 

sys.stdout.write("Displaying %5.1f %%                          \r" % (75.))
sys.stdout.flush()

fig = pl.figure(1)
pl.clf()
fig.subplots_adjust(left=0.12, bottom=0.1, right=0.96, top=0.95, wspace=0.26, hspace=0.26)

# We create a variable to store the index of the subplot
phi[too_low] = phi[too_low] + 360.
phi[too_high] = phi[too_high] - 360.

delta_longitude = long_of_peri_outer - long_of_peri_inner
delta_longitude = delta_longitude%(360.)
too_low = delta_longitude < ANGLE_MIN
too_high = delta_longitude > ANGLE_MAX
delta_longitude[too_low] = delta_longitude[too_low] + 360.
delta_longitude[too_high] = delta_longitude[too_high] - 360.


# We chose the number of plot in x and y axis for the p.multi
# environment in order to plot ALL the resonant angles and have x and
# y numbers as close on from another as possible. There are q+1
# resonant angles, the period ratio and w1 - w2, i.e q+3 plots
(nb_lines, nb_rows) = autiwa.get_subplot_shape(q+3)

# on trace les plots
myxfmt = ScalarFormatter(useOffset=True)
myxfmt._set_offset(1e5)
myxfmt.set_scientific(True)
myxfmt.set_powerlimits((-3, 3))

sys.stdout.write("Displaying %5.1f %%                          \r" % (75.))
sys.stdout.flush()

fig = pl.figure(1)
pl.clf()
fig.subplots_adjust(left=0.12, bottom=0.1, right=0.96, top=0.95, wspace=0.26, hspace=0.26)

# We create a variable to store the index of the subplot