Revision: 7345
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7345&view=rev
Author: jdh2358
Date: 2009-08-04 13:15:14 +0000 (Tue, 04 Aug 2009)
Log Message:
-----------
get data example
Modified Paths:
--------------
trunk/matplotlib/CHANGELOG
trunk/matplotlib/examples/pylab_examples/scatter_demo2.py
trunk/matplotlib/lib/matplotlib/__init__.py
trunk/matplotlib/lib/matplotlib/cbook.py
Added Paths:
-----------
trunk/matplotlib/examples/misc/mpl_data_demo.py
Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG 2009-08-04 13:11:35 UTC (rev 7344)
+++ trunk/matplotlib/CHANGELOG 2009-08-04 13:15:14 UTC (rev 7345)
@@ -1,3 +1,4 @@
+
2009-08-03 Add PathCollection; modify contourf to use complex
paths instead of simple paths with cuts. - EF
@@ -3,4 +4,8 @@
2009-08-03 Fixed boilerplate.py so it doesn't break the ReST docs. - JKS
+2009-07-31 Added cbook.get_mpl_data for urllib enabled fetching and
+ cacheing of data needed for examples. See
+ examples/misc/mpl_data_demo.py - JDH
+
======================================================================
Added: trunk/matplotlib/examples/misc/mpl_data_demo.py
===================================================================
--- trunk/matplotlib/examples/misc/mpl_data_demo.py
(rev 0)
+++ trunk/matplotlib/examples/misc/mpl_data_demo.py 2009-08-04 13:15:14 UTC
(rev 7345)
@@ -0,0 +1,12 @@
+ """
+ Grab mpl data from the ~/.matplotlib/mpl_data cache if it exists, else
+ fetch it from svn and cache it
+ """
+import matplotlib.cbook as cbook
+import matplotlib.pyplot as plt
+fname = cbook.get_mpl_data('lena.png', asfileobj=False)
+
+print 'fname', fname
+im = plt.imread(fname)
+plt.imshow(im)
+plt.show()
Modified: trunk/matplotlib/examples/pylab_examples/scatter_demo2.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/scatter_demo2.py 2009-08-04
13:11:35 UTC (rev 7344)
+++ trunk/matplotlib/examples/pylab_examples/scatter_demo2.py 2009-08-04
13:15:14 UTC (rev 7345)
@@ -1,7 +1,7 @@
"""
make a scatter plot with varying color and size arguments
"""
-import matplotlib
+import matplotlib
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
Modified: trunk/matplotlib/lib/matplotlib/__init__.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/__init__.py 2009-08-04 13:11:35 UTC (rev
7344)
+++ trunk/matplotlib/lib/matplotlib/__init__.py 2009-08-04 13:15:14 UTC (rev
7345)
@@ -487,6 +487,7 @@
always=False)
+
def get_example_data(fname):
"""
return a filehandle to one of the example files in mpl-data/example
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py 2009-08-04 13:11:35 UTC (rev
7344)
+++ trunk/matplotlib/lib/matplotlib/cbook.py 2009-08-04 13:15:14 UTC (rev
7345)
@@ -10,6 +10,8 @@
import numpy.ma as ma
from weakref import ref
+import matplotlib
+
major, minor1, minor2, s, tmp = sys.version_info
@@ -338,6 +340,55 @@
def is_scalar_or_string(val):
return is_string_like(val) or not iterable(val)
+
+
+def get_mpl_data(fname, asfileobj=True):
+ """
+ Check the cachedirectory ~/.matplotlib/mpl_data for an mpl_data
+ file. If it does not exist, fetch it with urllib from the mpl svn repo
+
+ http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/mpl_data/
+
+ and store it in the cachedir.
+
+ If asfileobj is True, a file object will be returned. Else the
+ path to the file as a string will be returned
+
+ To add a datafile to this directory, you need to check out
+ mpl_data from matplotlib svn::
+
+ svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/mpl_data
+
+ and svn add the data file you want to support. This is primarily
+ intended for use in mpl examples that need custom data
+ """
+
+ # TODO: how to handle stale data in the cache that has been
+ # updated from svn -- is there a clean http way to get the current
+ # revision number that will not leave us at the mercy of html
+ # changes at sf?
+
+
+ configdir = matplotlib.get_configdir()
+ cachedir = os.path.join(configdir, 'mpl_data')
+ if not os.path.exists(cachedir):
+ os.mkdir(cachedir)
+
+ cachefile = os.path.join(cachedir, fname)
+
+ if not os.path.exists(cachefile):
+ import urllib
+ url =
'http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/mpl_data/%s'%urllib.quote(fname)
+ matplotlib.verbose.report('Attempting to download %s to %s'%(url,
cachefile))
+ urllib.urlretrieve(url, filename=cachefile)
+ else:
+ matplotlib.verbose.report('Aleady have mpl_data %s'%fname)
+
+ if asfileobj:
+ return to_filehandle(cachefile)
+ else:
+ return cachefile
+
def flatten(seq, scalarp=is_scalar_or_string):
"""
this generator flattens nested containers such as
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins