| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,13 @@ | |||
| 1 | + | ||
| 1 | 2 | 2009-08-03 Add PathCollection; modify contourf to use complex | |
| 2 | 3 | paths instead of simple paths with cuts. - EF | |
| 3 | 4 | ||
| 4 | 5 | 2009-08-03 Fixed boilerplate.py so it doesn't break the ReST docs. - JKS | |
| 5 | 6 | ||
| 7 | + 2009-07-31 Added cbook.get_mpl_data for urllib enabled fetching and | ||
| 8 | + cacheing of data needed for examples. See | ||
| 9 | + examples/misc/mpl_data_demo.py - JDH | ||
| 10 | + | ||
| 6 | 11 | ====================================================================== | |
| 7 | 12 | ||
| 8 | 13 | 2009-07-31 Tagging 0.99.0.rc1 at 7314 - MGD | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,12 @@ | |||
| 1 | + """ | ||
| 2 | + Grab mpl data from the ~/.matplotlib/mpl_data cache if it exists, else | ||
| 3 | + fetch it from svn and cache it | ||
| 4 | + """ | ||
| 5 | + import matplotlib.cbook as cbook | ||
| 6 | + import matplotlib.pyplot as plt | ||
| 7 | + fname = cbook.get_mpl_data('lena.png', asfileobj=False) | ||
| 8 | + | ||
| 9 | + print 'fname', fname | ||
| 10 | + im = plt.imread(fname) | ||
| 11 | + plt.imshow(im) | ||
| 12 | + plt.show() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,7 @@ | |||
| 1 | 1 | """ | |
| 2 | 2 | make a scatter plot with varying color and size arguments | |
| 3 | 3 | """ | |
| 4 | - import matplotlib | ||
| 4 | + import matplotlib | ||
| 5 | 5 | import numpy as np | |
| 6 | 6 | import matplotlib.pyplot as plt | |
| 7 | 7 | import matplotlib.mlab as mlab | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -487,6 +487,7 @@ def _get_data_path_cached(): | |||
| 487 | 487 | always=False) | |
| 488 | 488 | ||
| 489 | 489 | ||
| 490 | + | ||
| 490 | 491 | def get_example_data(fname): | |
| 491 | 492 | """ | |
| 492 | 493 | return a filehandle to one of the example files in mpl-data/example | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,8 @@ | |||
| 10 | 10 | import numpy.ma as ma | |
| 11 | 11 | from weakref import ref | |
| 12 | 12 | ||
| 13 | + import matplotlib | ||
| 14 | + | ||
| 13 | 15 | major, minor1, minor2, s, tmp = sys.version_info | |
| 14 | 16 | ||
| 15 | 17 | ||
@@ -338,6 +340,55 @@ def to_filehandle(fname, flag='rU', return_opened=False): | |||
| 338 | 340 | def is_scalar_or_string(val): | |
| 339 | 341 | return is_string_like(val) or not iterable(val) | |
| 340 | 342 | ||
| 343 | + | ||
| 344 | + | ||
| 345 | + def get_mpl_data(fname, asfileobj=True): | ||
| 346 | + """ | ||
| 347 | + Check the cachedirectory ~/.matplotlib/mpl_data for an mpl_data | ||
| 348 | + file. If it does not exist, fetch it with urllib from the mpl svn repo | ||
| 349 | + | ||
| 350 | + http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/mpl_data/ | ||
| 351 | + | ||
| 352 | + and store it in the cachedir. | ||
| 353 | + | ||
| 354 | + If asfileobj is True, a file object will be returned. Else the | ||
| 355 | + path to the file as a string will be returned | ||
| 356 | + | ||
| 357 | + To add a datafile to this directory, you need to check out | ||
| 358 | + mpl_data from matplotlib svn:: | ||
| 359 | + | ||
| 360 | + svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/mpl_data | ||
| 361 | + | ||
| 362 | + and svn add the data file you want to support. This is primarily | ||
| 363 | + intended for use in mpl examples that need custom data | ||
| 364 | + """ | ||
| 365 | + | ||
| 366 | + # TODO: how to handle stale data in the cache that has been | ||
| 367 | + # updated from svn -- is there a clean http way to get the current | ||
| 368 | + # revision number that will not leave us at the mercy of html | ||
| 369 | + # changes at sf? | ||
| 370 | + | ||
| 371 | + | ||
| 372 | + configdir = matplotlib.get_configdir() | ||
| 373 | + cachedir = os.path.join(configdir, 'mpl_data') | ||
| 374 | + if not os.path.exists(cachedir): | ||
| 375 | + os.mkdir(cachedir) | ||
| 376 | + | ||
| 377 | + cachefile = os.path.join(cachedir, fname) | ||
| 378 | + | ||
| 379 | + if not os.path.exists(cachefile): | ||
| 380 | + import urllib | ||
| 381 | + url = 'http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/mpl_data/%s'%urllib.quote(fname) | ||
| 382 | + matplotlib.verbose.report('Attempting to download %s to %s'%(url, cachefile)) | ||
| 383 | + urllib.urlretrieve(url, filename=cachefile) | ||
| 384 | + else: | ||
| 385 | + matplotlib.verbose.report('Aleady have mpl_data %s'%fname) | ||
| 386 | + | ||
| 387 | + if asfileobj: | ||
| 388 | + return to_filehandle(cachefile) | ||
| 389 | + else: | ||
| 390 | + return cachefile | ||
| 391 | + | ||
| 341 | 392 | def flatten(seq, scalarp=is_scalar_or_string): | |
| 342 | 393 | """ | |
| 343 | 394 | this generator flattens nested containers such as | |
| Back | FazBrowse Home | New Git URL |
0 commit comments