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

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2a85769
adds encoding as a function parameter
katyhuff Jun 29, 2013
b300ef3
when dealing with unicode strings, isinstance(u, basestring) will ret…
katyhuff Jun 29, 2013
7eb7ec0
Merge branch 'master' into unicode_rc
katyhuff Jun 29, 2013
aede120
undid enccoding parameter. This can be added later if the encoding ge…
katyhuff Jun 29, 2013
55475a0
adds a test file and a template rc file for the rc_setup tests.
katyhuff Jun 29, 2013
8df2f0b
default test passes.
katyhuff Jun 29, 2013
55d4b44
autopep8'd the test file.
katyhuff Jun 29, 2013
1cfedb9
The matplotlibrc template docstring.hardcopy must use a colon rather …
katyhuff Jun 29, 2013
09a2450
because of commas, Impact and Western were being merged
katyhuff Jun 29, 2013
6d79027
uncomments the matplotlibrc template
katyhuff Jun 29, 2013
a41204d
errors arose for some (but not all) of these parameters inside apostr…
katyhuff Jun 29, 2013
3840623
The matplotlibrc should match the default, which is (f, ctrl+f)
katyhuff Jun 29, 2013
1042544
template test passes.
katyhuff Jun 30, 2013
be48e7d
got rid of print statements from debugging
katyhuff Jun 30, 2013
09bf2dd
unicode test runs
katyhuff Jun 30, 2013
cda758d
merged unicode solution
katyhuff Jun 30, 2013
1976db5
unicode test passes
katyhuff Jun 30, 2013
7302c31
errant space.
katyhuff Jun 30, 2013
febaa0d
updates matplotlibrc.template to mat the defaults in the rcsetup module
katyhuff Jun 30, 2013
c3bfe6c
Merge branch 'master' into rc_fixes
katyhuff Jun 30, 2013
fa3f07d
getting up to date with master
katyhuff Jul 1, 2013
6bd355f
Merge branch 'master' into rc_fixes
katyhuff Jul 1, 2013
15b8b57
makes a proper docstring and removes the assert
katyhuff Jul 2, 2013
4ce865c
fixed typerror
katyhuff Jul 2, 2013
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
Prev Previous commit
Next Next commit
template test passes.
  • Loading branch information
katyhuff committed Jun 30, 2013
commit 10425446bf21438d3259285b67173b1502836930
92 changes: 49 additions & 43 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,15 @@ def validate_colorlist(s):
return [validate_color(c) for c in s]


def validate_string(s):
'return a clean string'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a nitpick here: let's use "proper" docstrings. I also don't feel like the function name reflect what the function does.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, I was just trying to match the style (and definition description verbosity) of rest of the file. Mind if I change them all to docstrings?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I, personally, have no problem with that.

assert isinstance(s, basestring)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not a big fan of doing asserts in code. Not only do they raise exception that are hard to understand, but they are also only evaluated when the code is not run as optimized. Maybe we should do a proper verification, and raise a more explicit error message?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure. will do.

return s.strip("'").strip()

def validate_stringlist(s):
'return a list'
if type(s) in (str, unicode):
return [v.strip() for v in s.split(',')]
return [validate_string(v) for v in s.split(',')]
else:
assert type(s) in [list, tuple]
return [str(v) for v in s]
Expand Down Expand Up @@ -402,11 +407,13 @@ def deprecate_svg_embed_char_paths(value):


def validate_hinting(s):
if s in (True, False):
return s
if s.lower() in ('auto', 'native', 'either', 'none'):
return s.lower()
raise ValueError("hinting should be 'auto', 'native', 'either' or 'none'")
try :
return validate_bool(s)
except ValueError :
if s.lower() in ('auto', 'native', 'either', 'none'):
return s.lower()
else :
raise ValueError("hinting should be 'auto', 'native', 'either' or 'none'")

validate_pgf_texsystem = ValidateInStrings('pgf.texsystem',
['xelatex', 'lualatex', 'pdflatex'])
Expand Down Expand Up @@ -495,7 +502,7 @@ def __call__(self, s):
# line props
'lines.linewidth': [1.0, validate_float], # line width in points
'lines.linestyle': ['-', str], # solid line
'lines.color': ['b', validate_color], # blue
'lines.color': ['blue', validate_color], # b=blue
'lines.marker': ['None', str], # black
'lines.markeredgewidth': [0.5, validate_float],
'lines.markersize': [6, validate_float], # markersize, in points
Expand All @@ -507,17 +514,17 @@ def __call__(self, s):

## patch props
'patch.linewidth': [1.0, validate_float], # line width in points
'patch.edgecolor': ['k', validate_color], # black
'patch.facecolor': ['b', validate_color], # blue
'patch.edgecolor': ['black', validate_color], # k=black
'patch.facecolor': ['blue', validate_color], # b=blue
'patch.antialiased': [True, validate_bool], # antialised (no jaggies)


## font props
'font.family': ['sans-serif', validate_stringlist], # used by text object
'font.style': ['normal', str],
'font.variant': ['normal', str],
'font.stretch': ['normal', str],
'font.weight': ['normal', str],
'font.family': ['sans-serif', validate_string], # used by text object
'font.style': ['normal', validate_string],
'font.variant': ['normal', validate_string],
'font.stretch': ['normal', validate_string],
'font.weight': ['normal', validate_string],
'font.size': [12, validate_float], # Base font size in points
'font.serif': [['Bitstream Vera Serif', 'DejaVu Serif',
'New Century Schoolbook', 'Century Schoolbook L',
Expand All @@ -539,7 +546,7 @@ def __call__(self, s):
validate_stringlist],

# text props
'text.color': ['k', validate_color], # black
'text.color': ['black', validate_color], # k=black
'text.usetex': [False, validate_bool],
'text.latex.unicode': [False, validate_bool],
'text.latex.preamble': [[''], validate_stringlist],
Expand All @@ -554,7 +561,7 @@ def __call__(self, s):
'mathtext.tt': ['monospace', validate_font_properties],
'mathtext.it': ['serif:italic', validate_font_properties],
'mathtext.bf': ['serif:bold', validate_font_properties],
'mathtext.sf': ['sans\-serif', validate_font_properties],
'mathtext.sf': ['sans', validate_font_properties],
'mathtext.fontset': ['cm', validate_fontset],
'mathtext.default': ['it', validate_mathtext_default],
'mathtext.fallback_to_cm': [True, validate_bool],
Expand All @@ -572,16 +579,16 @@ def __call__(self, s):
# axes props
'axes.axisbelow': [False, validate_bool],
'axes.hold': [True, validate_bool],
'axes.facecolor': ['w', validate_color], # background color; white
'axes.edgecolor': ['k', validate_color], # edge color; black
'axes.facecolor': ['white', validate_color], # background color; w=white
'axes.edgecolor': ['black', validate_color], # edge color; k=black
'axes.linewidth': [1.0, validate_float], # edge linewidth
'axes.titlesize': ['large', validate_fontsize], # fontsize of the
# axes title
'axes.grid': [False, validate_bool], # display grid or not
'axes.labelsize': ['medium', validate_fontsize], # fontsize of the
# x any y labels
'axes.labelweight': ['normal', str], # fontsize of the x any y labels
'axes.labelcolor': ['k', validate_color], # color of axis label
'axes.labelcolor': ['black', validate_color], # color of axis label
'axes.formatter.limits': [[-7, 7], validate_nseq_int(2)],
# use scientific notation if log10
# of the axis range is smaller than the
Expand Down Expand Up @@ -666,7 +673,7 @@ def __call__(self, s):
'ytick.labelsize': ['medium', validate_fontsize],
'ytick.direction': ['in', str], # direction of yticks

'grid.color': ['k', validate_color], # grid color
'grid.color': ['black', validate_color], # grid color
'grid.linestyle': [':', str], # dotted
'grid.linewidth': [0.5, validate_float], # in points
'grid.alpha': [1.0, validate_float],
Expand All @@ -677,7 +684,7 @@ def __call__(self, s):
'figure.figsize': [[8.0, 6.0], validate_nseq_float(2)],
'figure.dpi': [80, validate_float], # DPI
'figure.facecolor': ['0.75', validate_color], # facecolor; scalar gray
'figure.edgecolor': ['w', validate_color], # edgecolor; white
'figure.edgecolor': ['white', validate_color], # edgecolor; w=white
'figure.frameon': [True, validate_bool],
'figure.autolayout': [False, validate_bool],
'figure.max_open_warning': [20, validate_int],
Expand All @@ -697,8 +704,8 @@ def __call__(self, s):

## Saving figure's properties
'savefig.dpi': [100, validate_float], # DPI
'savefig.facecolor': ['w', validate_color], # facecolor; white
'savefig.edgecolor': ['w', validate_color], # edgecolor; white
'savefig.facecolor': ['white', validate_color], # facecolor; w=white
'savefig.edgecolor': ['white', validate_color], # edgecolor; w=white
'savefig.frameon': [True, validate_bool],
'savefig.orientation': ['portrait', validate_orientation], # edgecolor;
#white
Expand Down Expand Up @@ -753,53 +760,52 @@ def __call__(self, s):
'plugins.directory': ['.matplotlib_plugins', str],

'path.simplify': [True, validate_bool],
'path.simplify_threshold': [1.0 / 9.0, ValidateInterval(0.0, 1.0)],
'path.simplify_threshold': [0.1, ValidateInterval(0.0, 1.0)],
'path.snap': [True, validate_bool],
'path.sketch': [None, validate_sketch],
'path.effects': [[], validate_any],
'agg.path.chunksize': [0, validate_int], # 0 to disable chunking;

# key-mappings (multi-character mappings should be a list/tuple)
'keymap.fullscreen': [('f', 'ctrl+f'), validate_stringlist],
'keymap.fullscreen': [['f', 'ctrl+f'], validate_stringlist],
'keymap.home': [['h', 'r', 'home'], validate_stringlist],
'keymap.back': [['left', 'c', 'backspace'], validate_stringlist],
'keymap.forward': [['right', 'v'], validate_stringlist],
'keymap.pan': ['p', validate_stringlist],
'keymap.zoom': ['o', validate_stringlist],
'keymap.save': [('s', 'ctrl+s'), validate_stringlist],
'keymap.quit': [('ctrl+w', 'cmd+w'), validate_stringlist],
'keymap.grid': ['g', validate_stringlist],
'keymap.yscale': ['l', validate_stringlist],
'keymap.pan': [['p'], validate_stringlist],
'keymap.zoom': [['o'], validate_stringlist],
'keymap.save': [['s', 'ctrl+s'], validate_stringlist],
'keymap.quit': [['ctrl+w', 'cmd+w'], validate_stringlist],
'keymap.grid': [['g'], validate_stringlist],
'keymap.yscale': [['l'], validate_stringlist],
'keymap.xscale': [['k', 'L'], validate_stringlist],
'keymap.all_axes': ['a', validate_stringlist],
'keymap.all_axes': [['a'], validate_stringlist],

# sample data
'examples.directory': ['', str],
'examples.directory': ['', validate_string],

# Animation settings
'animation.writer': ['ffmpeg', validate_movie_writer],
'animation.codec': ['mpeg4', str],
'animation.codec': ['mpeg4', validate_string],
'animation.bitrate': [-1, validate_int],
# Controls image format when frames are written to disk
'animation.frame_format': ['png', validate_movie_frame_fmt],
# Path to FFMPEG binary. If just binary name, subprocess uses $PATH.
'animation.ffmpeg_path': ['ffmpeg', str],
'animation.ffmpeg_path': ['ffmpeg', validate_string],

## Additional arguments for ffmpeg movie writer (using pipes)
'animation.ffmpeg_args': ['', validate_stringlist],
'animation.ffmpeg_args': [[''], validate_stringlist],
# Path to AVConv binary. If just binary name, subprocess uses $PATH.
'animation.avconv_path': ['avconv', str],
'animation.avconv_path': ['avconv', validate_string],
# Additional arguments for avconv movie writer (using pipes)
'animation.avconv_args': ['', validate_stringlist],
'animation.avconv_args': [[''], validate_stringlist],
# Path to MENCODER binary. If just binary name, subprocess uses $PATH.
'animation.mencoder_path': ['mencoder', str],
'animation.mencoder_path': ['mencoder', validate_string],
# Additional arguments for mencoder movie writer (using pipes)
'animation.mencoder_args': ['', validate_stringlist],
'animation.mencoder_args': [[''], validate_stringlist],
# Path to convert binary. If just binary name, subprocess uses $PATH
'animation.convert_path': ['convert', str],
'animation.convert_path': ['convert', validate_string],
# Additional arguments for mencoder movie writer (using pipes)

'animation.convert_args': ['', validate_stringlist]}
'animation.convert_args': [[''], validate_stringlist]}


if __name__ == '__main__':
Expand Down
23 changes: 13 additions & 10 deletions lib/matplotlib/tests/test_rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
from matplotlib.tests import assert_str_equal

templaterc = os.path.join(os.path.dirname(__file__), 'test_rcsetup.rc')

deprecated = ['svg.embed_char_paths', 'savefig.extension']

def test_defaults():
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's nice to have some unit tests for this! Thanks!

# the default values should be successfully set by this class
deprecated = ['svg.embed_char_paths', 'savefig.extension']
with mpl.rc_context(rc=mpl.rcsetup.defaultParams):
for k, v in mpl.rcsetup.defaultParams.iteritems():
if k not in deprecated:
Expand All @@ -17,16 +16,20 @@ def test_defaults():

def test_template():
# the current matplotlibrc.template should validate successfully
mpl.rc_file(templaterc)
with mpl.rc_context(fname=templaterc):
for k, v in mpl.rcsetup.defaultParams.iteritems():
if mpl.rcParams[k] != v[0]:
print k
print v[0]
print mpl.rcParams[k]
print "---------------"
assert mpl.rcParams[k] == v[0]

if k not in deprecated:
if mpl.rcParams[k] != v[0]:
print k
print "Expected : ", v[0]
print "Expected type", type(v[0])
print "Actual : ", mpl.rcParams[k]
print "Actual type : ", type(mpl.rcParams[k])
print "---------------"
if isinstance(v[0], basestring):
assert mpl.rcParams[k] in [v[0], v[0].lower()]
else :
assert mpl.rcParams[k] == v[0]

def test_unicode():
# unicode formatted valid strings should validate.
Expand Down
53 changes: 26 additions & 27 deletions lib/matplotlib/tests/test_rcsetup.rc
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ lines.color : blue # has no affect on plot(); see axes.color_cycle
lines.marker : None # the default marker
lines.markeredgewidth : 0.5 # the line width around the marker symbol
lines.markersize : 6 # markersize, in points
lines.dash_joinstyle : miter # miter|round|bevel
lines.dash_joinstyle : round # miter|round|bevel
lines.dash_capstyle : butt # butt|round|projecting
lines.solid_joinstyle : miter # miter|round|bevel
lines.solid_joinstyle : round # miter|round|bevel
lines.solid_capstyle : projecting # butt|round|projecting
lines.antialiased : True # render lines in antialised (no jaggies)

Expand Down Expand Up @@ -129,19 +129,19 @@ patch.antialiased : True # render patches in antialised (no jaggies)
font.family : sans-serif
font.style : normal
font.variant : normal
font.weight : medium
font.weight : normal
font.stretch : normal
# note that font.size controls default text sizes. To configure
# special text sizes tick labels, axes, labels, title, etc, see the rc
# settings for axes and ticks. Special text sizes can be defined
# relative to font.size, using the following values: xx-small, x-small,
# small, medium, large, x-large, xx-large, larger, or smaller
font.size : 12.0
font.serif : Bitstream Vera Serif, New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, serif
font.sans-serif : Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif
font.serif : Bitstream Vera Serif, DejaVu Serif, New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, serif
font.sans-serif : Bitstream Vera Sans, DejaVu Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif
font.cursive : Apple Chancery, Textile, Zapf Chancery, Sand, cursive
font.fantasy : Comic Sans MS, Chicago, Charcoal, Impact, Western, fantasy
font.monospace : Bitstream Vera Sans Mono, Andale Mono, Nimbus Mono L, Courier New, Courier, Fixed, Terminal, monospace
font.monospace : Bitstream Vera Sans Mono, DejaVu Sans Mono, Andale Mono, Nimbus Mono L, Courier New, Courier, Fixed, Terminal, monospace

### TEXT
# text properties used by text.Text. See
Expand Down Expand Up @@ -181,7 +181,7 @@ text.dvipnghack : None # some versions of dvipng don't handle alpha
# correction off. None will try and
# guess based on your dvipng version

text.hinting : auto # May be one of the following:
text.hinting : True # May be one of the following:
# 'none': Perform no hinting
# 'auto': Use freetype's autohinter
# 'native': Use the hinting information in the
Expand Down Expand Up @@ -292,7 +292,7 @@ legend.fancybox : False # if True, use a rounded box for the
legend.isaxes : True
legend.numpoints : 2 # the number of points in the legend line
legend.fontsize : large
legend.borderpad : 0.5 # border whitespace in fontsize units
legend.borderpad : 0.4 # border whitespace in fontsize units
legend.markerscale : 1.0 # the relative size of legend markers vs. original
# the following dimensions are in axes coords
legend.labelspacing : 0.5 # the vertical space between the legend entries in fraction of fontsize
Expand Down Expand Up @@ -351,7 +351,7 @@ agg.path.chunksize : 0 # 0 to disable; values in the range
path.simplify : True # When True, simplify paths by removing "invisible"
# points to reduce file size and increase rendering
# speed
path.simplify_threshold : 0.1 # The threshold of similarity below which
path.simplify_threshold : 0.1 # The threshold of similarity below which
# vertices will be removed in the simplification
# process
path.snap : True # When True, rectilinear axis-aligned paths will be snapped to
Expand Down Expand Up @@ -432,35 +432,34 @@ verbose.fileo : sys.stdout # a log filename, sys.stdout or sys.stderr
# Customize these settings according to your needs.
# Leave the field(s) empty if you don't need a key-map. (i.e., fullscreen : '')

keymap.fullscreen : f # toggling
keymap.fullscreen : f, ctrl+f # toggling
keymap.home : h, r, home # home or reset mnemonic
keymap.back : left, c, backspace # forward / backward keys to enable
keymap.forward : right, v # left handed quick navigation
keymap.pan : p # pan mnemonic
keymap.zoom : o # zoom mnemonic
keymap.save : s # saving current figure
keymap.save : s, ctrl+s # saving current figure
keymap.quit : ctrl+w, cmd+w # close the current figure
keymap.grid : g # switching on/off a grid in current axes
keymap.yscale : l # toggle scaling of y-axes ('log'/'linear')
keymap.xscale : L, k # toggle scaling of x-axes ('log'/'linear')
keymap.xscale : k, L # toggle scaling of x-axes ('log'/'linear')
keymap.all_axes : a # enable all axes

# Control location of examples data files
examples.directory : '' # directory to look in for custom installation

###ANIMATION settings
animation.writer : ffmpeg # MovieWriter 'backend' to use
animation.codec : mp4 # Codec to use for writing movie
animation.bitrate: -1 # Controls size/quality tradeoff for movie.
# -1 implies let utility auto-determine
animation.frame_format: png # Controls frame format used by temp files
animation.ffmpeg_path: 'ffmpeg' # Path to ffmpeg binary. Without full path
# $PATH is searched
animation.ffmpeg_args: '' # Additional arguments to pass to ffmpeg
animation.avconv_path: 'avconv' # Path to avconv binary. Without full path
# $PATH is searched
animation.avconv_args: '' # Additional arguments to pass to avconv
animation.mencoder_path: 'mencoder'
# Path to mencoder binary. Without full path
# $PATH is searched
animation.mencoder_args: '' # Additional arguments to pass to mencoder
animation.writer : ffmpeg # MovieWriter 'backend' to use
animation.codec : mpeg4 # Codec to use for writing movie
animation.bitrate: -1 # Controls size/quality tradeoff for movie.
# -1 implies let utility auto-determine
animation.frame_format: png # Controls frame format used by temp files
animation.ffmpeg_path: 'ffmpeg' # Path to ffmpeg binary. Without full path
# $PATH is searched
animation.ffmpeg_args: '' # Additional arguments to pass to ffmpeg
animation.avconv_path: 'avconv' # Path to avconv binary. Without full path
# $PATH is searched
animation.avconv_args: '' # Additional arguments to pass to avconv
animation.mencoder_path: 'mencoder' # Path to mencoder binary. Without full path
# $PATH is searched
animation.mencoder_args: '' # Additional arguments to pass to mencoder