Trouble with x-axis labeling

Hello All!

I searched for my problem and while I found similar questions this seemed to
be a unique problem.

I am creating an image that is six vertically stacked subplots and I want
only the axis of the bottom subplot to be labelled. However, as you can see
from the image I attached it's picking the wrong subplot to label. It's as
if the program is not understanding that there is one more plot. If I just
plot five plots than everything works. I'm not sure what is going wrong with
me code. It would be extremely helpful if someone could take a look.

xlabel = ["",5000,5500,6000,6500,7000,""]
plt.figure()

night = (glob.glob('*_sci.txt'))
for i in range(0,len(night)):
        # Read in data for each night
        wave = np.loadtxt(night[i], usecols=[0])
        flux = np.loadtxt(night[i], usecols=[1])
        # Create subplots
        temp = 610 +i
        spect = plt.subplot(temp,sharex=True)
        # Draw plot
        plt.plot(wave, flux, color="green")
        plt.subplots_adjust(hspace = 0.001)
        spect.set_autoscaley_on(False)
        pylab.ylim([0,0.5e-13])
        # Make y tick makers
        temp = tic.MaxNLocator(3)
        plt.gca().yaxis.set_major_locator(tic.MaxNLocator(prune='lower'))
        plt.gca().yaxis.set_major_locator(tic.MaxNLocator(prune='upper'))
        spect.yaxis.set_major_locator(temp)
        # Get rid of redundant x tick labels
        if i < len(night)-1:
                plt.setp(spect.get_xticklabels(), visible=False)

spect.set_xticklabels(xlabel, minor=False)
plt.xlabel("Observed Wavelength $(\AA)$",fontsize=16)

<http://matplotlib.1069221.n5.nabble.com/file/n40916/Example.png>

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Trouble-with-x-axis-labeling-tp40916.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

plt.subplot() uses 1-based indexing. So, the first plot you make is "610"
because i == 0 in the first iteration. This corresponds to the *last"
subplot you actually want (i.e., the bottom one). If you just have a 611 +
i, the problem would be fixed. Btw, there is an ax.label_outer() function
that would make the code easier to read.

Ben Root

···

On Wed, Apr 17, 2013 at 11:54 AM, Alexa <alexa7890@...287...> wrote:

Hello All!

I searched for my problem and while I found similar questions this seemed
to
be a unique problem.

I am creating an image that is six vertically stacked subplots and I want
only the axis of the bottom subplot to be labelled. However, as you can see
from the image I attached it's picking the wrong subplot to label. It's as
if the program is not understanding that there is one more plot. If I just
plot five plots than everything works. I'm not sure what is going wrong
with
me code. It would be extremely helpful if someone could take a look.

xlabel = ["",5000,5500,6000,6500,7000,""]
plt.figure()

night = (glob.glob('*_sci.txt'))
for i in range(0,len(night)):
        # Read in data for each night
        wave = np.loadtxt(night[i], usecols=[0])
        flux = np.loadtxt(night[i], usecols=[1])
        # Create subplots
        temp = 610 +i
        spect = plt.subplot(temp,sharex=True)
        # Draw plot
        plt.plot(wave, flux, color="green")
        plt.subplots_adjust(hspace = 0.001)
        spect.set_autoscaley_on(False)
        pylab.ylim([0,0.5e-13])
        # Make y tick makers
        temp = tic.MaxNLocator(3)
        plt.gca().yaxis.set_major_locator(tic.MaxNLocator(prune='lower'))
        plt.gca().yaxis.set_major_locator(tic.MaxNLocator(prune='upper'))
        spect.yaxis.set_major_locator(temp)
        # Get rid of redundant x tick labels
        if i < len(night)-1:
                plt.setp(spect.get_xticklabels(), visible=False)

spect.set_xticklabels(xlabel, minor=False)
plt.xlabel("Observed Wavelength \(\\AA\)",fontsize=16)

<http://matplotlib.1069221.n5.nabble.com/file/n40916/Example.png&gt;

Hi Ben,

Thank you for your quick reply. That did the trick! I will into
ax.label_outer() , thanks for the suggestion.

- Alexa

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Trouble-with-x-axis-labeling-tp40916p40918.html
Sent from the matplotlib - users mailing list archive at Nabble.com.