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

Skip to content

Commit 94d044e

Browse files
olgabotMrngilles
authored andcommitted
Added rcParams for removing specific spines
Added xtick.position and ytick.position to rcsetup.py trying to fix Travis CI failure on 2.6 Removed x-y position parameter from rc default dic Added style rcParam + stylesheet recursion scatter, fill_between and fill_betweenx use color_cycle Added rcParameters for boxplot + validations functions Added rcParameter to choose grid axis display Comment tweaks added boxplot.flierprops + line length fixes fix: unable to get substyles from path or URL removed boxplot.fliersymbol because not needed Fixed boxplot checks spine removing modified + removed : from docstring removed color_cycle from scatter, fill_between, fill_betweenx Original behaviour of axes.grid + working rc axes.grid.orientation Fixed the get_substyles function to accept dictionnaries Fix PEP8 + OrderedDict issues in Travis Modified how we get rcParams in the boxplot method tried fixing test issues + pep8 fix travis for patch_artist linestyle issue removed the style rcParam to put it in an other PR used setdefault function + validation function + Error message fixed pep8 error fixed pep8 error (again) Comments and style fixes Fixed whiskers and bootstrap rcParams use Added tests for boxplot rc parameters and fixes added spine rc parameter test added test for axes.grid.axis rc parameter + typo fix in spines test Typo fix
1 parent e405a68 commit 94d044e

File tree

11 files changed

+1411
-17
lines changed

11 files changed

+1411
-17
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2950,11 +2950,11 @@ def xywhere(xs, ys, mask):
29502950

29512951
return errorbar_container # (l0, caplines, barcols)
29522952

2953-
def boxplot(self, x, notch=False, sym=None, vert=True, whis=1.5,
2954-
positions=None, widths=None, patch_artist=False,
2953+
def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
2954+
positions=None, widths=None, patch_artist=None,
29552955
bootstrap=None, usermedians=None, conf_intervals=None,
2956-
meanline=False, showmeans=False, showcaps=True,
2957-
showbox=True, showfliers=True, boxprops=None, labels=None,
2956+
meanline=None, showmeans=None, showcaps=None,
2957+
showbox=None, showfliers=None, boxprops=None, labels=None,
29582958
flierprops=None, medianprops=None, meanprops=None,
29592959
capprops=None, whiskerprops=None, manage_xticks=True):
29602960
"""
@@ -3114,11 +3114,60 @@ def boxplot(self, x, notch=False, sym=None, vert=True, whis=1.5,
31143114
31153115
.. plot:: mpl_examples/statistics/boxplot_demo.py
31163116
"""
3117+
# If defined in matplotlibrc, apply the value from rc file
3118+
# Overridden if argument is passed
3119+
if whis is None:
3120+
whis = rcParams['boxplot.whiskers']
3121+
if bootstrap is None:
3122+
bootstrap = rcParams['boxplot.bootstrap']
31173123
bxpstats = cbook.boxplot_stats(x, whis=whis, bootstrap=bootstrap,
31183124
labels=labels)
3119-
# make sure we have a dictionary
3120-
if flierprops is None:
3121-
flierprops = dict()
3125+
if notch is None:
3126+
notch = rcParams['boxplot.notch']
3127+
if vert is None:
3128+
vert = rcParams['boxplot.vertical']
3129+
if patch_artist is None:
3130+
patch_artist = rcParams['boxplot.patchartist']
3131+
if meanline is None:
3132+
meanline = rcParams['boxplot.meanline']
3133+
if showmeans is None:
3134+
showmeans = rcParams['boxplot.showmeans']
3135+
if showcaps is None:
3136+
showcaps = rcParams['boxplot.showcaps']
3137+
if showbox is None:
3138+
showbox = rcParams['boxplot.showbox']
3139+
if showfliers is None:
3140+
showfliers = rcParams['boxplot.showfliers']
3141+
3142+
3143+
def _update_dict(dictionary, rc_name, properties):
3144+
""" Loads properties in the dictionary from rc file if not already
3145+
in the dictionary"""
3146+
rc_str = 'boxplot.{0}.{1}'
3147+
if dictionary is None:
3148+
dictionary = dict()
3149+
for prop_dict in properties:
3150+
dictionary.setdefault(prop_dict,
3151+
rcParams[rc_str.format(rc_name, prop_dict)])
3152+
return dictionary
3153+
3154+
# Common property dictionnaries loading from rc
3155+
flier_props = ['color', 'marker', 'markerfacecolor', 'markeredgecolor',
3156+
'markersize', 'linestyle', 'linewidth']
3157+
default_props = ['color', 'linewidth', 'linestyle']
3158+
3159+
boxprops = _update_dict(boxprops, 'boxprops', default_props)
3160+
whiskerprops = _update_dict(whiskerprops, 'whiskerprops',
3161+
default_props)
3162+
capprops = _update_dict(capprops, 'capprops', default_props)
3163+
medianprops = _update_dict(medianprops, 'medianprops', default_props)
3164+
meanprops = _update_dict(meanprops, 'meanprops', default_props)
3165+
flierprops = _update_dict(flierprops, 'flierprops', flier_props)
3166+
3167+
if patch_artist:
3168+
boxprops['linestyle'] = 'solid'
3169+
boxprops['edgecolor'] = boxprops.pop('color')
3170+
31223171
# if non-default sym value, put it into the flier dictionary
31233172
# the logic for providing the default symbol ('b+') now lives
31243173
# in bxp in the initial value of final_flierprops
@@ -3162,8 +3211,8 @@ def boxplot(self, x, notch=False, sym=None, vert=True, whis=1.5,
31623211

31633212
if conf_intervals is not None:
31643213
if np.shape(conf_intervals)[0] != len(bxpstats):
3165-
raise ValueError('conf_intervals length not '
3166-
'compatible with x')
3214+
err_mess = 'conf_intervals length not compatible with x'
3215+
raise ValueError(err_mess)
31673216
else:
31683217
for stats, ci in zip(bxpstats, conf_intervals):
31693218
if ci is not None:
@@ -3680,7 +3729,7 @@ def scatter(self, x, y, s=20, c=None, marker='o', cmap=None, norm=None,
36803729
if facecolors is not None:
36813730
c = facecolors
36823731
else:
3683-
c = 'b' # the original default
3732+
c = 'b' # The original default
36843733

36853734
self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)
36863735
x = self.convert_xunits(x)

lib/matplotlib/axes/_base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,9 @@ def cla(self):
921921
self.collections = [] # collection.Collection instances
922922
self.containers = []
923923

924-
self.grid(self._gridOn, which=rcParams['axes.grid.which'])
924+
self.grid(False) # Disable grid on init to use rcParameter
925+
self.grid(self._gridOn, which=rcParams['axes.grid.which'],
926+
axis=rcParams['axes.grid.axis'])
925927
props = font_manager.FontProperties(
926928
size=rcParams['axes.titlesize'],
927929
weight=rcParams['axes.titleweight']

lib/matplotlib/mpl-data/stylelib/bmh.mplstyle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Author: Cameron Davidson-Pilon, original styles from Bayesian Methods for Hackers
2-
# https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/
2+
# https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/
33

44
lines.linewidth : 2.0
55

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

22-
legend.fancybox: True
22+
legend.fancybox: True
23+

lib/matplotlib/rcsetup.py

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ def validate_int(s):
139139
except ValueError:
140140
raise ValueError('Could not convert "%s" to int' % s)
141141

142+
def validate_int_or_None(s):
143+
"""if not None, tries to validate as an int"""
144+
if s=='None':
145+
s = None
146+
if s is None:
147+
return None
148+
try:
149+
return int(s)
150+
except ValueError:
151+
raise ValueError('Could not convert "%s" to int' % s)
142152

143153
def validate_fonttype(s):
144154
"""
@@ -352,6 +362,22 @@ def validate_font_properties(s):
352362
'verbose',
353363
['silent', 'helpful', 'debug', 'debug-annoying'])
354364

365+
def validate_whiskers(s):
366+
if s=='range':
367+
return 'range'
368+
else:
369+
try:
370+
v = validate_nseq_float(2)(s)
371+
return v
372+
except:
373+
try:
374+
v = float(s)
375+
return v
376+
except:
377+
err_str = ("Not a valid whisker value ['range',"
378+
"float, (float, float)]")
379+
raise ValueError(err_str)
380+
355381

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

474-
validate_axis_locator = ValidateInStrings('major', ['minor','both','major'])
500+
validate_axis_locator = ValidateInStrings('major', ['minor', 'both', 'major'])
475501

476502
def validate_bbox(s):
477503
if isinstance(s, six.string_types):
@@ -530,6 +556,7 @@ def __call__(self, s):
530556
(self.vmax, s))
531557
return s
532558

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

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

604+
## Boxplot properties
605+
'boxplot.notch': [False, validate_bool],
606+
'boxplot.vertical': [True, validate_bool],
607+
'boxplot.whiskers': [1.5, validate_whiskers],
608+
'boxplot.bootstrap': [None, validate_int_or_None],
609+
'boxplot.patchartist': [False, validate_bool],
610+
'boxplot.showmeans': [False, validate_bool],
611+
'boxplot.showcaps': [True, validate_bool],
612+
'boxplot.showbox': [True, validate_bool],
613+
'boxplot.showfliers': [True, validate_bool],
614+
'boxplot.meanline': [False, validate_bool],
615+
616+
'boxplot.flierprops.color': ['b', validate_color],
617+
'boxplot.flierprops.marker': ['+', six.text_type],
618+
'boxplot.flierprops.markerfacecolor': ['b', validate_color],
619+
'boxplot.flierprops.markeredgecolor': ['k', validate_color],
620+
'boxplot.flierprops.markersize': [6, validate_float],
621+
'boxplot.flierprops.linestyle': ['-', six.text_type],
622+
'boxplot.flierprops.linewidth': [1.0, validate_float],
623+
624+
'boxplot.boxprops.color': ['b', validate_color],
625+
'boxplot.boxprops.linewidth': [1.0, validate_float],
626+
'boxplot.boxprops.linestyle': ['-', six.text_type],
627+
628+
'boxplot.whiskerprops.color': ['b', validate_color],
629+
'boxplot.whiskerprops.linewidth': [1.0, validate_float],
630+
'boxplot.whiskerprops.linestyle': ['--', six.text_type],
631+
632+
'boxplot.capprops.color': ['k', validate_color],
633+
'boxplot.capprops.linewidth': [1.0, validate_float],
634+
'boxplot.capprops.linestyle': ['-', six.text_type],
635+
636+
'boxplot.medianprops.color': ['r', validate_color],
637+
'boxplot.medianprops.linewidth': [1.0, validate_float],
638+
'boxplot.medianprops.linestyle': ['-', six.text_type],
639+
640+
'boxplot.meanprops.color': ['r', validate_color],
641+
'boxplot.meanprops.linewidth': [1.0, validate_float],
642+
'boxplot.meanprops.linestyle': ['-', six.text_type],
577643

578644
## font props
579645
'font.family': [['sans-serif'], validate_stringlist], # used by text object
@@ -648,6 +714,12 @@ def __call__(self, s):
648714
'axes.facecolor': ['w', validate_color], # background color; white
649715
'axes.edgecolor': ['k', validate_color], # edge color; black
650716
'axes.linewidth': [1.0, validate_float], # edge linewidth
717+
718+
'axes.spines.left': [True, validate_bool], # Set visibility of axes
719+
'axes.spines.right': [True, validate_bool], # 'spines', the lines
720+
'axes.spines.bottom': [True, validate_bool], # around the chart
721+
'axes.spines.top': [True, validate_bool], # denoting data boundary
722+
651723
'axes.titlesize': ['large', validate_fontsize], # fontsize of the
652724
# axes title
653725
'axes.titleweight': ['normal', six.text_type], # font weight of axes title
@@ -656,6 +728,8 @@ def __call__(self, s):
656728
# default draw on 'major'
657729
# 'minor' or 'both' kind of
658730
# axis locator
731+
'axes.grid.axis': ['both', validate_grid_axis], # grid type.
732+
# Can be 'x', 'y', 'both'
659733
'axes.labelsize': ['medium', validate_fontsize], # fontsize of the
660734
# x any y labels
661735
'axes.labelpad': [5.0, validate_float], # space between label and axis

lib/matplotlib/spines.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ def linear_spine(cls, axes, spine_type, **kwargs):
467467
else:
468468
raise ValueError('unable to make path for spine "%s"' % spine_type)
469469
result = cls(axes, spine_type, path, **kwargs)
470+
result.set_visible(rcParams['axes.spines.{0}'.format(spine_type)])
471+
470472
return result
471473

472474
@classmethod
Binary file not shown.

0 commit comments

Comments
 (0)