Return a sample data file. *fname* is a path relative to the :file:`mpl-data/sample_data` directory. If *asfileobj* is `True` return a file object, otherwise just a file path. Sample data files are stored in the 'mpl-data/sample_data' directory within the Matplotlib package.
(fname, asfileobj=True)
| 596 | |
| 597 | |
| 598 | def get_sample_data(fname, asfileobj=True): |
| 599 | """ |
| 600 | Return a sample data file. *fname* is a path relative to the |
| 601 | :file:`mpl-data/sample_data` directory. If *asfileobj* is `True` |
| 602 | return a file object, otherwise just a file path. |
| 603 | |
| 604 | Sample data files are stored in the 'mpl-data/sample_data' directory within |
| 605 | the Matplotlib package. |
| 606 | |
| 607 | If the filename ends in .gz, the file is implicitly ungzipped. If the |
| 608 | filename ends with .npy or .npz, and *asfileobj* is `True`, the file is |
| 609 | loaded with `numpy.load`. |
| 610 | """ |
| 611 | path = _get_data_path('sample_data', fname) |
| 612 | if asfileobj: |
| 613 | suffix = path.suffix.lower() |
| 614 | if suffix == '.gz': |
| 615 | return gzip.open(path) |
| 616 | elif suffix in ['.npy', '.npz']: |
| 617 | return np.load(path) |
| 618 | elif suffix in ['.csv', '.xrc', '.txt']: |
| 619 | return path.open('r') |
| 620 | else: |
| 621 | return path.open('rb') |
| 622 | else: |
| 623 | return str(path) |
| 624 | |
| 625 | |
| 626 | def _get_data_path(*args): |
searching dependent graphs…