I have a short script to plot 20 years of river flow data. I can use the plot_date command to create a plot, using this snippet: f = figure() ax1 = f.add_subplot(111) ax1.plot_date(dates0,y1,'g', label='observed', xdate=True,visible=True) ax1.plot_date(dates1,y2,'r', label='simulated', xdate=True,visible=True) years = YearLocator(1, month=6, day=30) # every year months = MonthLocator(1) # every month ax1.set_xlim(date2num(datetime.date(1990,1,1)),date2num(datetime.date(1999,12,31))) ax1.xaxis.set_major_locator(years) ax1.xaxis.set_minor_locator(months) labels = ax1.get_xticklabels() setp(labels, fontsize=8,visible=True) The problem is with the x-axis (time axis) labels when I add a second subplot, to add the next time segment. I change the above to ax1 = f.add_subplot(211), and then: ax2 = f.add_subplot(212) ax2.plot_date(dates0,y1,'g') #plots the time series ax2.plot_date(dates1,y2,'r') #need to call twice, unlike plot, plot_date takes one set ax2.set_xlim(date2num(datetime.date(2000,1,1)),date2num(datetime.date(2009,12,31))) ax2.xaxis.set_major_locator(years) ax2.xaxis.set_minor_locator(months) setp(labels, fontsize=8,visible=True) The x-axis labels only appear for the last subplot. I'm guessing that plot_date assumes that more than one subplot must share a time axis. There must be a simple way to stop plot_date from doing this, if this is indeed the problem. Any guidance would be appreciated. Thanks, Ed
I have a short script to plot 20 years of river flow data. I can use the plot_date command to create a plot, using this snippet: f = figure() ax1 = f.add_subplot(111) ax1.plot_date(dates0,y1,'g', label='observed', xdate=True,visible=True) ax1.plot_date(dates1,y2,'r', label='simulated', xdate=True,visible=True) years = YearLocator(1, month=6, day=30) # every year months = MonthLocator(1) # every month ax1.set_xlim(date2num(datetime.date(1990,1,1)),date2num(datetime.date(1999,12,31))) ax1.xaxis.set_major_locator(years) ax1.xaxis.set_minor_locator(months) labels = ax1.get_xticklabels() setp(labels, fontsize=8,visible=True) The problem is with the x-axis (time axis) labels when I add a second subplot, to add the next time segment. I change the above to ax1 = f.add_subplot(211), and then: ax2 = f.add_subplot(212) ax2.plot_date(dates0,y1,'g') #plots the time series ax2.plot_date(dates1,y2,'r') #need to call twice, unlike plot, plot_date takes one set ax2.set_xlim(date2num(datetime.date(2000,1,1)),date2num(datetime.date(2009,12,31))) ax2.xaxis.set_major_locator(years) ax2.xaxis.set_minor_locator(months) setp(labels, fontsize=8,visible=True) The x-axis labels only appear for the last subplot. I'm guessing that plot_date assumes that more than one subplot must share a time axis. There must be a simple way to stop plot_date from doing this, if this is indeed the problem. Any guidance would be appreciated. Thanks, Ed
i use something like that: from datetime import datetime, timedelta import matplotlib.pyplot as pl import matplotlib.ticker as ticker import matplotlib.dates as mdates dates1 = [datetime(2005,5,11)+n*timedelta(days=1) for n in range(500)] dates2 = [datetime(... ax1 = pl.subplot(2,1,1) ax1.plot(dates1, y1, 'r') ax1.fmt_xdata = mdates.DateFormatter('%Y-%m-%d') ax2 = pl.subplot(2,1,2) ax2.plot(dates2, ... that's what you want? regards, yoshi