Remove xlabel

Hi
I’m plotting data associated with dates.
I have two problems.

The first one is that the xlabel “date” is displayed despite that haven’t set Matplotlib to do so.

My code is the following one :

        fig = plt.figure(1)

        title_to_display=str("Entropy, Kullback-LeiblerL, symmetric KL and resistor KL from %s to %s"%(IP_list_RTT[i][0].split("_")[1],IP_list_RTT[i][0].split("_")[2]))
       
        ax_1 = fig.add_subplot(2,2,1)
        ax_1.plot(dates_RTT,data_RTT,'r-')
       
        ax_2 = twinx()
        ax_2.plot(dates_distances,entropy_list)
        ax_2.plot(dates_distances,kullback_leibler_list)
        ax_2.plot(dates_distances,symmetric_kullback_leibler_list)
        ax_2.plot(dates_distances,resistor_average_kullback_leibler_list)
        ax_2.yaxis.tick_right()
       
        title(title_to_display,fontsize=size_font_title)
        ax_1.grid(True)
        ax_1.xaxis.set_major_formatter(formatter_1)
        ax_2.xaxis.set_major_formatter(formatter_2)
        labels_x1 = ax_1.get_xticklabels()
        labels_x2 = ax_2.get_xticklabels()
        setp(labels_x1, rotation=rotation_x_label, fontsize=size_font_x_label)           
        setp(labels_x2, rotation=rotation_x_label, fontsize=size_font_x_label)

All the variables relatives to the display (rotation_x_label,size_font_x_label,size_font_title) are defined before.
If I add xlabel(“tutut”), I just get “tutut” print over the two previous “date” (one for ax_1 and one for ax_2).

It also looks like there is two x tick labels formatted displayed.
I tried to define two formatters with one empty and one “normal” and assign them to the two different axes that I’m using with something like this :
formatter_1 = DateFormatter(’’)
formatter_2 = DateFormatter(’%H-%M-%S’)
and then :
ax_1.xaxis.set_major_formatter(formatter_1)
ax_2.xaxis.set_major_formatter(formatter_2)

But it doesn’t work.
If the empty formatter is the first one, it looks that both x tick labels are displayed at the same time (just as before). And if the empty formatter is the second, none of the x tick labels are displayed.

Thanks in advance for the help.
Regards.
Johan Mazel

Hi
I'm plotting data associated with dates.
I have two problems.

The first one is that the xlabel "date" is displayed despite that haven't
set Matplotlib to do so.

Yes, that was meant to be a feature but it is mainly an annoyance.
I've removed it from svn. You can set the xlabel to be blank on any
axes with

ax.set_xlabel('')

My code is the following one :

            fig = plt.figure(1)

            title_to_display=str("Entropy, Kullback-LeiblerL, symmetric KL
and resistor KL from %s to
%s"%(IP_list_RTT[i][0].split("_")[1],IP_list_RTT[i][0].split("_")[2]))

            ax_1 = fig.add_subplot(2,2,1)
            ax_1.plot(dates_RTT,data_RTT,'r-')

            ax_2 = twinx()
            ax_2.plot(dates_distances,entropy_list)
            ax_2.plot(dates_distances,kullback_leibler_list)
            ax_2.plot(dates_distances,symmetric_kullback_leibler_list)

ax_2.plot(dates_distances,resistor_average_kullback_leibler_list)
            ax_2.yaxis.tick_right()

            title(title_to_display,fontsize=size_font_title)
            ax_1.grid(True)
            ax_1.xaxis.set_major_formatter(formatter_1)
            ax_2.xaxis.set_major_formatter(formatter_2)
            labels_x1 = ax_1.get_xticklabels()
            labels_x2 = ax_2.get_xticklabels()
            setp(labels_x1, rotation=rotation_x_label,
fontsize=size_font_x_label)
            setp(labels_x2, rotation=rotation_x_label,
fontsize=size_font_x_label)

All the variables relatives to the display
(rotation_x_label,size_font_x_label,size_font_title) are defined before.
If I add xlabel("tutut"), I just get "tutut" print over the two previous
"date" (one for ax_1 and one for ax_2).

It also looks like there is two x tick labels formatted displayed.
I tried to define two formatters with one empty and one "normal" and assign
them to the two different axes that I'm using with something like this :
            formatter_1 = DateFormatter('')
            formatter_2 = DateFormatter('%H-%M-%S')
and then :
            ax_1.xaxis.set_major_formatter(formatter_1)
            ax_2.xaxis.set_major_formatter(formatter_2)

With twinx, you get shared x-axis, and because they are shared they
share the same locator and formatter. What you need to do is make the
ones on axes 1 *invisible*

for label in ax1.get_xticklabels():
    label.set_visible(False)

BTW, for other uses, yo umay want to use the NullFormatter when you
want no strings. But this doesn't work with shared axes so use the
invisible trick.

JDH

···

On Tue, May 20, 2008 at 10:32 AM, Johan Mazel <johan.mazel@...287...> wrote: