|
From: <jd...@us...> - 2008-06-09 17:49:15
|
Revision: 5437
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5437&view=rev
Author: jdh2358
Date: 2008-06-09 10:47:43 -0700 (Mon, 09 Jun 2008)
Log Message:
-----------
added date index plot faq
Modified Paths:
--------------
trunk/matplotlib/doc/devel/outline.rst
trunk/matplotlib/doc/faq/howto_faq.rst
trunk/matplotlib/doc/make.py
Modified: trunk/matplotlib/doc/devel/outline.rst
===================================================================
--- trunk/matplotlib/doc/devel/outline.rst 2008-06-09 17:47:32 UTC (rev 5436)
+++ trunk/matplotlib/doc/devel/outline.rst 2008-06-09 17:47:43 UTC (rev 5437)
@@ -22,7 +22,7 @@
date plots John has author ?
working with data John has author Darren
custom ticking ? no author ?
-masked data Eric has author ?
+masked data Eric has author ?
text ? no author ?
patches ? no author ?
legends ? no author ?
Modified: trunk/matplotlib/doc/faq/howto_faq.rst
===================================================================
--- trunk/matplotlib/doc/faq/howto_faq.rst 2008-06-09 17:47:32 UTC (rev 5436)
+++ trunk/matplotlib/doc/faq/howto_faq.rst 2008-06-09 17:47:43 UTC (rev 5437)
@@ -91,3 +91,41 @@
----------------------------------
TODO
+
+
+.. _date-index-plots:
+
+How do I skip dates where there is no data?
+===========================================
+
+When plotting time series, eg financial time series, one often wants
+to leave out days on which there is no data, eg weekends. By passing
+in dates on the x-xaxis, you get large horizontal gaps on periods when
+there is not data. The solution is to pass in some proxy x-data, eg
+evenly sampled indicies, and then use a custom formatter to format
+these as dates. The example below shows how to use an 'index formatter'
+to achieve the desired plot
+
+ import numpy as np
+ import matplotlib.pyplot as plt
+ import matplotlib.mlab as mlab
+ import matplotlib.ticker as ticker
+
+ r = mlab.csv2rec('../data/aapl.csv')
+ r.sort()
+ r = r[-30:] # get the last 30 days
+
+ N = len(r)
+ ind = np.arange(N) # the evenly spaced plot indices
+
+ def format_date(x, pos=None):
+ thisind = np.clip(int(x+0.5), 0, N-1)
+ return r.date[thisind].strftime('%Y-%m-%d')
+
+ fig = plt.figure()
+ ax = fig.add_subplot(111)
+ ax.plot(ind, r.adj_close, 'o-')
+ ax.xaxis.set_major_formatter(ticker.FuncFormatter(format_date))
+ fig.autofmt_xdate()
+
+ plt.show()
Modified: trunk/matplotlib/doc/make.py
===================================================================
--- trunk/matplotlib/doc/make.py 2008-06-09 17:47:32 UTC (rev 5436)
+++ trunk/matplotlib/doc/make.py 2008-06-09 17:47:43 UTC (rev 5437)
@@ -14,6 +14,10 @@
except OSError:
pass
+def sf():
+ 'push a copy to the sf site'
+ os.system('cd build; rsync -avz html jd...@ma...:/home/groups/m/ma/matplotlib/htdocs/doc/ -essh')
+
def figs():
os.system('cd users/figures/ && python make.py')
@@ -56,6 +60,7 @@
'html':html,
'latex':latex,
'clean':clean,
+ 'sf':sf,
'all':all,
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|