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

Skip to content

Addition of RC parameters #4218

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 3 commits into from
Jul 12, 2015
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
70 changes: 59 additions & 11 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2950,19 +2950,19 @@ def xywhere(xs, ys, mask):

return errorbar_container # (l0, caplines, barcols)

def boxplot(self, x, notch=False, sym=None, vert=True, whis=1.5,
positions=None, widths=None, patch_artist=False,
def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
positions=None, widths=None, patch_artist=None,
bootstrap=None, usermedians=None, conf_intervals=None,
meanline=False, showmeans=False, showcaps=True,
showbox=True, showfliers=True, boxprops=None, labels=None,
meanline=None, showmeans=None, showcaps=None,
showbox=None, showfliers=None, boxprops=None, labels=None,
Copy link
Member

Choose a reason for hiding this comment

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

I think the doc string (below) needs update to reflect these changes

flierprops=None, medianprops=None, meanprops=None,
capprops=None, whiskerprops=None, manage_xticks=True):
"""
Make a box and whisker plot.

Call signature::

boxplot(self, x, notch=False, sym='b+', vert=True, whis=1.5,
boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
positions=None, widths=None, patch_artist=False,
bootstrap=None, usermedians=None, conf_intervals=None,
meanline=False, showmeans=False, showcaps=True,
Expand Down Expand Up @@ -3114,11 +3114,59 @@ def boxplot(self, x, notch=False, sym=None, vert=True, whis=1.5,

.. plot:: mpl_examples/statistics/boxplot_demo.py
"""
# If defined in matplotlibrc, apply the value from rc file
# Overridden if argument is passed
if whis is None:
whis = rcParams['boxplot.whiskers']
Copy link
Member

Choose a reason for hiding this comment

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

If I understand this correctly, then a bad situation can arise. If someone has an rc file with a different value for boxplot.whiskers, but explicitly passes in a value for whis, then the rcfile's value takes precedence. That would be incorrect. Why not set the default value of whis to None and test for that?

I have similar concerns for bootstrap because it completely ignores the possibility that the user explicitly sets some value for it.

if bootstrap is None:
bootstrap = rcParams['boxplot.bootstrap']
bxpstats = cbook.boxplot_stats(x, whis=whis, bootstrap=bootstrap,
labels=labels)
# make sure we have a dictionary
if flierprops is None:
flierprops = dict()
if notch is None:
notch = rcParams['boxplot.notch']
if vert is None:
vert = rcParams['boxplot.vertical']
if patch_artist is None:
patch_artist = rcParams['boxplot.patchartist']
if meanline is None:
meanline = rcParams['boxplot.meanline']
if showmeans is None:
showmeans = rcParams['boxplot.showmeans']
if showcaps is None:
showcaps = rcParams['boxplot.showcaps']
if showbox is None:
showbox = rcParams['boxplot.showbox']
if showfliers is None:
showfliers = rcParams['boxplot.showfliers']

def _update_dict(dictionary, rc_name, properties):
""" Loads properties in the dictionary from rc file if not already
in the dictionary"""
rc_str = 'boxplot.{0}.{1}'
if dictionary is None:
dictionary = dict()
for prop_dict in properties:
dictionary.setdefault(prop_dict,
rcParams[rc_str.format(rc_name, prop_dict)])
return dictionary

# Common property dictionnaries loading from rc
flier_props = ['color', 'marker', 'markerfacecolor', 'markeredgecolor',
'markersize', 'linestyle', 'linewidth']
default_props = ['color', 'linewidth', 'linestyle']

boxprops = _update_dict(boxprops, 'boxprops', default_props)
whiskerprops = _update_dict(whiskerprops, 'whiskerprops',
default_props)
capprops = _update_dict(capprops, 'capprops', default_props)
medianprops = _update_dict(medianprops, 'medianprops', default_props)
meanprops = _update_dict(meanprops, 'meanprops', default_props)
flierprops = _update_dict(flierprops, 'flierprops', flier_props)

if patch_artist:
boxprops['linestyle'] = 'solid'
boxprops['edgecolor'] = boxprops.pop('color')

# if non-default sym value, put it into the flier dictionary
# the logic for providing the default symbol ('b+') now lives
# in bxp in the initial value of final_flierprops
Expand Down Expand Up @@ -3162,8 +3210,8 @@ def boxplot(self, x, notch=False, sym=None, vert=True, whis=1.5,

if conf_intervals is not None:
if np.shape(conf_intervals)[0] != len(bxpstats):
raise ValueError('conf_intervals length not '
'compatible with x')
err_mess = 'conf_intervals length not compatible with x'
raise ValueError(err_mess)
else:
for stats, ci in zip(bxpstats, conf_intervals):
if ci is not None:
Expand Down Expand Up @@ -3680,7 +3728,7 @@ def scatter(self, x, y, s=20, c=None, marker='o', cmap=None, norm=None,
if facecolors is not None:
c = facecolors
else:
c = 'b' # the original default
c = 'b' # The original default

self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)
x = self.convert_xunits(x)
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,9 @@ def cla(self):
self.collections = [] # collection.Collection instances
self.containers = []

self.grid(self._gridOn, which=rcParams['axes.grid.which'])
self.grid(False) # Disable grid on init to use rcParameter
self.grid(self._gridOn, which=rcParams['axes.grid.which'],
axis=rcParams['axes.grid.axis'])
props = font_manager.FontProperties(
size=rcParams['axes.titlesize'],
weight=rcParams['axes.titleweight']
Expand Down
5 changes: 3 additions & 2 deletions lib/matplotlib/mpl-data/stylelib/bmh.mplstyle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Author: Cameron Davidson-Pilon, original styles from Bayesian Methods for Hackers
# https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/
# https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/

lines.linewidth : 2.0

Expand All @@ -19,4 +19,5 @@ axes.titlesize: x-large
axes.labelsize: large
axes.color_cycle: 348ABD, A60628, 7A68A6, 467821, D55E00, CC79A7, 56B4E9, 009E73, F0E442, 0072B2

legend.fancybox: True
legend.fancybox: True

76 changes: 75 additions & 1 deletion lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ def validate_int(s):
except ValueError:
raise ValueError('Could not convert "%s" to int' % s)

def validate_int_or_None(s):
"""if not None, tries to validate as an int"""
if s=='None':
s = None
if s is None:
return None
try:
return int(s)
except ValueError:
raise ValueError('Could not convert "%s" to int' % s)

def validate_fonttype(s):
"""
Expand Down Expand Up @@ -352,6 +362,22 @@ def validate_font_properties(s):
'verbose',
['silent', 'helpful', 'debug', 'debug-annoying'])

def validate_whiskers(s):
if s=='range':
return 'range'
else:
try:
v = validate_nseq_float(2)(s)
return v
except:
try:
v = float(s)
return v
except:
err_str = ("Not a valid whisker value ['range',"
"float, (float, float)]")
raise ValueError(err_str)


def deprecate_savefig_extension(value):
warnings.warn("savefig.extension is deprecated. Use savefig.format "
Expand Down Expand Up @@ -471,7 +497,7 @@ def validate_hinting(s):
validate_movie_frame_fmt = ValidateInStrings('animation.frame_format',
['png', 'jpeg', 'tiff', 'raw', 'rgba'])

validate_axis_locator = ValidateInStrings('major', ['minor','both','major'])
validate_axis_locator = ValidateInStrings('major', ['minor', 'both', 'major'])

def validate_bbox(s):
if isinstance(s, six.string_types):
Expand Down Expand Up @@ -530,6 +556,7 @@ def __call__(self, s):
(self.vmax, s))
return s

validate_grid_axis = ValidateInStrings('axes.grid.axis', ['x', 'y', 'both'])

# a map from key -> value, converter
defaultParams = {
Expand Down Expand Up @@ -574,6 +601,45 @@ def __call__(self, s):
'patch.facecolor': ['b', validate_color], # blue
'patch.antialiased': [True, validate_bool], # antialised (no jaggies)

## Boxplot properties
'boxplot.notch': [False, validate_bool],
'boxplot.vertical': [True, validate_bool],
'boxplot.whiskers': [1.5, validate_whiskers],
'boxplot.bootstrap': [None, validate_int_or_None],
'boxplot.patchartist': [False, validate_bool],
'boxplot.showmeans': [False, validate_bool],
'boxplot.showcaps': [True, validate_bool],
'boxplot.showbox': [True, validate_bool],
'boxplot.showfliers': [True, validate_bool],
'boxplot.meanline': [False, validate_bool],

'boxplot.flierprops.color': ['b', validate_color],
'boxplot.flierprops.marker': ['+', six.text_type],
'boxplot.flierprops.markerfacecolor': ['b', validate_color],
'boxplot.flierprops.markeredgecolor': ['k', validate_color],
'boxplot.flierprops.markersize': [6, validate_float],
'boxplot.flierprops.linestyle': ['-', six.text_type],
'boxplot.flierprops.linewidth': [1.0, validate_float],

'boxplot.boxprops.color': ['b', validate_color],
'boxplot.boxprops.linewidth': [1.0, validate_float],
'boxplot.boxprops.linestyle': ['-', six.text_type],

'boxplot.whiskerprops.color': ['b', validate_color],
'boxplot.whiskerprops.linewidth': [1.0, validate_float],
'boxplot.whiskerprops.linestyle': ['--', six.text_type],

'boxplot.capprops.color': ['k', validate_color],
'boxplot.capprops.linewidth': [1.0, validate_float],
'boxplot.capprops.linestyle': ['-', six.text_type],

'boxplot.medianprops.color': ['r', validate_color],
'boxplot.medianprops.linewidth': [1.0, validate_float],
'boxplot.medianprops.linestyle': ['-', six.text_type],

'boxplot.meanprops.color': ['r', validate_color],
'boxplot.meanprops.linewidth': [1.0, validate_float],
'boxplot.meanprops.linestyle': ['-', six.text_type],

## font props
'font.family': [['sans-serif'], validate_stringlist], # used by text object
Expand Down Expand Up @@ -648,6 +714,12 @@ def __call__(self, s):
'axes.facecolor': ['w', validate_color], # background color; white
'axes.edgecolor': ['k', validate_color], # edge color; black
'axes.linewidth': [1.0, validate_float], # edge linewidth

'axes.spines.left': [True, validate_bool], # Set visibility of axes
'axes.spines.right': [True, validate_bool], # 'spines', the lines
'axes.spines.bottom': [True, validate_bool], # around the chart
'axes.spines.top': [True, validate_bool], # denoting data boundary

'axes.titlesize': ['large', validate_fontsize], # fontsize of the
# axes title
'axes.titleweight': ['normal', six.text_type], # font weight of axes title
Expand All @@ -656,6 +728,8 @@ def __call__(self, s):
# default draw on 'major'
# 'minor' or 'both' kind of
# axis locator
'axes.grid.axis': ['both', validate_grid_axis], # grid type.
# Can be 'x', 'y', 'both'
'axes.labelsize': ['medium', validate_fontsize], # fontsize of the
# x any y labels
'axes.labelpad': [5.0, validate_float], # space between label and axis
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/spines.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ def linear_spine(cls, axes, spine_type, **kwargs):
else:
raise ValueError('unable to make path for spine "%s"' % spine_type)
result = cls(axes, spine_type, path, **kwargs)
result.set_visible(rcParams['axes.spines.{0}'.format(spine_type)])

return result

@classmethod
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading