[a9d5684] | 1 | # This program is public domain |
---|
| 2 | """ |
---|
| 3 | Configure plotter for plottools. |
---|
| 4 | |
---|
| 5 | This must be imported first in __init__.py for plottools. |
---|
| 6 | |
---|
| 7 | If your application uses matplotlib outside plottools, then |
---|
| 8 | please do the following at the start of your application: |
---|
| 9 | |
---|
| 10 | # Select matplotlib version and backend |
---|
[d7bb526] | 11 | import sas.sasgui.plottools.config |
---|
[a9d5684] | 12 | |
---|
| 13 | Note that plottools requires particular versions of matplotlib |
---|
| 14 | and a particular backend. As of this writing it is the WXAgg |
---|
| 15 | backend for matplotlib>=0.98. |
---|
| 16 | |
---|
| 17 | The plottools package uses pkg_resources if available to select |
---|
| 18 | the correct version of matplotlib. If you need multiple matplotlib |
---|
| 19 | versions in your path, be sure to use "easy_install -m" for all |
---|
| 20 | of them. If a version is installed without "-m" that does not |
---|
| 21 | meet the requirements, then pkg_resources.require() will fail, |
---|
| 22 | even if you have installed a suitable version with "-m". In this |
---|
| 23 | case you will need to fix up your site-packages directory, |
---|
| 24 | probably by removing site-packages/matplotlib and the associated |
---|
| 25 | egg file for that version, and reinstalling with "-m". You may |
---|
| 26 | also need to edit site-packages/easy-install.pth. |
---|
| 27 | """ |
---|
| 28 | import sys |
---|
| 29 | |
---|
| 30 | __all__ = [] |
---|
| 31 | |
---|
| 32 | plot_version = "0.98" |
---|
[cad617b] | 33 | #plot_backend = "WXAgg" |
---|
| 34 | plot_backend = "Qt4Agg" |
---|
[a9d5684] | 35 | |
---|
| 36 | # Sort out matplotlib version |
---|
| 37 | import matplotlib |
---|
[6d05e1d] | 38 | #try: |
---|
| 39 | # import pkg_resources |
---|
| 40 | # pkg_resources.require("matplotlib>=" + plot_version) |
---|
| 41 | #except: |
---|
| 42 | # from distutils.version import LooseVersion as Version |
---|
| 43 | # if Version(matplotlib.__version__) < Version(plot_version): |
---|
| 44 | # msg = "Matplotlib version must be %s or newer" % (plot_version, ) |
---|
| 45 | # raise ImportError(msg) |
---|
[a9d5684] | 46 | |
---|
| 47 | # Sort out matplotlib backend |
---|
| 48 | #import matplotlib |
---|
| 49 | if 'matplotlib.backends' not in sys.modules: |
---|
| 50 | # if no backend yet, be sure to use the correct one |
---|
| 51 | matplotlib.use(plot_backend) |
---|
| 52 | elif matplotlib.get_backend() != plot_backend: |
---|
| 53 | # if a backend has already been selected, make sure it is the correct one. |
---|
[6d05e1d] | 54 | #raise ImportError("Matplotlib not using backend " + plot_backend) |
---|
| 55 | pass |
---|
[cafa75f] | 56 | |
---|
| 57 | # set global plot style |
---|
| 58 | param = 'legend.handletextpad' |
---|
| 59 | if param not in matplotlib.rcParams: param = 'legend.handletextsep' |
---|
| 60 | matplotlib.rcParams[param] = 0.05 |
---|
| 61 | matplotlib.rcParams['legend.numpoints'] = 1 |
---|
[d3d67f0] | 62 | |
---|
| 63 | # this should happen after initial matplotlib configuration |
---|
| 64 | from .toolbar import NavigationToolBar |
---|
| 65 | from matplotlib.backends import backend_wxagg |
---|
| 66 | backend_wxagg.NavigationToolbar2WxAgg = NavigationToolBar |
---|
| 67 | |
---|
| 68 | # CRUFT: bumps 0.7.5.6 and older uses wrong toolbar |
---|
| 69 | backend_wxagg.NavigationToolbar2Wx = NavigationToolBar |
---|