Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Tidy up the matplotlib.__init__ documentation. #1950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions doc/api/matplotlib_configuration_api.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
The top level :mod:`matplotlib` module
======================================

.. automodule:: matplotlib
:members: rc, rcdefaults, use
:undoc-members:
:show-inheritance:

.. py:currentmodule:: matplotlib

.. autofunction:: use

.. autofunction:: get_backend

.. py:data:: matplotlib.rcParams

An instance of :class:`RcParams` for handling default matplotlib values.

.. autofunction:: rc

.. autofunction::rcdefaults

.. autofunction::rc_file

.. autofunction::rc_context

.. autofunction:: matplotlib_fname

.. autofunction::rc_file_defaults

.. autofunction::interactive

.. autofunction::is_interactive

.. autoclass:: RcParams

.. autofunction:: rc_params

.. autofunction:: rc_params_from_file

.. autoclass:: rc_context
7 changes: 4 additions & 3 deletions doc/sphinxext/gen_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ def gen_gallery(app, doctree):
fh.close()

for key in app.builder.status_iterator(
iter(thumbnails.keys()), "generating thumbnails... ",
length=len(thumbnails)):
image.thumbnail(key, thumbnails[key], 0.3)
iter(thumbnails.keys()), "generating thumbnails... ",
length=len(thumbnails)):
if out_of_date(key, thumbnails[key]):
image.thumbnail(key, thumbnails[key], 0.3)


def setup(app):
Expand Down
52 changes: 27 additions & 25 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ def _get_configdir():
configdir = os.environ.get('MPLCONFIGDIR')
if configdir is not None:
if not os.path.exists(configdir):
from matplotlib.cbook import mkdirs
mkdirs(configdir)
if not _is_writable_dir(configdir):
return _create_tmp_config_dir()
Expand Down Expand Up @@ -631,9 +632,9 @@ def get_example_data(fname):

def get_py2exe_datafiles():
datapath = get_data_path()
head, tail = os.path.split(datapath)
_, tail = os.path.split(datapath)
d = {}
for root, dirs, files in os.walk(datapath):
for root, _, files in os.walk(datapath):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a style opinion, not a demand for change: I much prefer the original; the use of the bare underscore makes this sort of thing less readable and slightly ugly to my eye. In the case of the path.split(), an alternative is to index it with [-1].

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Thanks @efiring. I only did this because my editor was shouting at me that dirs was unused - the underscores use is not mentioned in PEP8 (though there is an interesting question on http://stackoverflow.com/questions/11486148/unused-variable-naming-in-python).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the use of underscores: it makes explicit that those variable are not used in this file, which is a convention in python and some other languages (perl?). IMO, we should stick to convention as much as possible.

Also, that makes pyflakes not happy.

# Need to explicitly remove cocoa_agg files or py2exe complains
# NOTE I dont know why, but do as previous version
if 'Matplotlib.nib' in files:
Expand All @@ -647,7 +648,7 @@ def get_py2exe_datafiles():

def matplotlib_fname():
"""
Return the path to the rc file
Return the path to the rc file used by matplotlib.

Search order:

Expand All @@ -656,9 +657,7 @@ def matplotlib_fname():
* HOME/.matplotlib/matplotlibrc
* MATPLOTLIBDATA/matplotlibrc


"""

oldname = os.path.join(os.getcwd(), '.matplotlibrc')
if os.path.exists(oldname):
try:
Expand Down Expand Up @@ -820,13 +819,14 @@ def find_all(self, pattern):


def rc_params(fail_on_error=False):
'Return the default params updated from the values in the rc file'

"""Return a :class:`matplotlib.RcParams` instance from the
default matplotlib rc file.
"""
fname = matplotlib_fname()
if not os.path.exists(fname):
# this should never happen, default in mpl-data should always be found
message = 'could not find rc file; returning defaults'
ret = RcParams([ (key, default) for key, (default, converter) in \
ret = RcParams([(key, default) for key, (default, _) in \
defaultParams.iteritems() ])
warnings.warn(message)
return ret
Expand All @@ -835,29 +835,31 @@ def rc_params(fail_on_error=False):


def rc_params_from_file(fname, fail_on_error=False):
"""Load and return params from fname."""

"""Return a :class:`matplotlib.RcParams` instance from the
contents of the given filename.
"""
cnt = 0
rc_temp = {}
with open(fname) as fd:
for line in fd:
cnt += 1
strippedline = line.split('#',1)[0].strip()
strippedline = line.split('#', 1)[0].strip()
if not strippedline: continue
tup = strippedline.split(':',1)
if len(tup) !=2:
warnings.warn('Illegal line #%d\n\t%s\n\tin file "%s"'%\
tup = strippedline.split(':', 1)
if len(tup) != 2:
warnings.warn('Illegal line #%d\n\t%s\n\tin file "%s"' % \
(cnt, line, fname))
continue
key, val = tup
key = key.strip()
val = val.strip()
if key in rc_temp:
warnings.warn('Duplicate key in file "%s", line #%d'%(fname,cnt))
warnings.warn('Duplicate key in file "%s", line #%d' % \
(fname, cnt))
rc_temp[key] = (val, line, cnt)

ret = RcParams([ (key, default) for key, (default, converter) in \
defaultParams.iteritems() ])
ret = RcParams([(key, default) for key, (default, _) in \
defaultParams.iteritems()])

for key in ('verbose.level', 'verbose.fileo'):
if key in rc_temp:
Expand Down Expand Up @@ -1033,20 +1035,20 @@ class rc_context(object):

This allows one to do::

>>> with mpl.rc_context(fname='screen.rc'):
... plt.plot(x, a)
... with mpl.rc_context(fname='print.rc'):
... plt.plot(x, b)
... plt.plot(x, c)
with mpl.rc_context(fname='screen.rc'):
plt.plot(x, a)
with mpl.rc_context(fname='print.rc'):
plt.plot(x, b)
plt.plot(x, c)

The 'a' vs 'x' and 'c' vs 'x' plots would have settings from
'screen.rc', while the 'b' vs 'x' plot would have settings from
'print.rc'.

A dictionary can also be passed to the context manager::

>>> with mpl.rc_context(rc={'text.usetex': True}, fname='screen.rc'):
... plt.plot(x, a)
with mpl.rc_context(rc={'text.usetex': True}, fname='screen.rc'):
plt.plot(x, a)

The 'rc' dictionary takes precedence over the settings loaded from
'fname'. Passing a dictionary only is also valid.
Expand Down Expand Up @@ -1133,7 +1135,7 @@ def use(arg, warn=True, force=False):
reload(sys.modules['matplotlib.backends'])

def get_backend():
"Returns the current backend."
"""Return the name of the current backend."""
return rcParams['backend']

def interactive(b):
Expand Down