SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Ed M. <ed....@gm...> - 2011年11月29日 21:20:33
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
From: Ed M. <em...@en...> - 2011年11月30日 11:01:59
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
From: Yoshi R. <yo...@ro...> - 2011年11月30日 16:01:37
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
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /