Skip to content

Commit

Permalink
Merge branch 'v2.0.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Nov 30, 2015
2 parents 47f2233 + 00b74bd commit f420992
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 11 deletions.
10 changes: 7 additions & 3 deletions doc/users/whats_new/ticks_rcparams.rst
@@ -1,6 +1,10 @@
New rcParams
------------

The parameters `xtick.top`, `xtick.bottom`, `ytick.left`
and `ytick.right` were added to control where the ticks
are drawn.
The parameters ``xtick.top``, ``xtick.bottom``, ``ytick.left``
and ``ytick.right`` were added to control where the ticks
are drawn.

``hist.bins`` to control the default number of bins to use in
`~matplotlib.axes.Axes.hist`. This can be an `int`, a list of floats, or
``'auto'`` if numpy >= 1.11 is installed.
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_axes.py
Expand Up @@ -4442,7 +4442,7 @@ def stackplot(self, x, *args, **kwargs):
label_namer=None)
def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
cmap=None, norm=None, arrowsize=1, arrowstyle='-|>',
minlength=0.1, transform=None, zorder=1, start_points=None):
minlength=0.1, transform=None, zorder=2, start_points=None):
if not self._hold:
self.cla()
stream_container = mstream.streamplot(self, x, y, u, v,
Expand Down
8 changes: 7 additions & 1 deletion lib/matplotlib/axes/_base.py
Expand Up @@ -1136,7 +1136,13 @@ def set_color_cycle(self, clist):
"""
cbook.warn_deprecated(
'1.5', name='set_color_cycle', alternative='set_prop_cycle')
self.set_prop_cycle('color', clist)
if clist is None:
# Calling set_color_cycle() or set_prop_cycle() with None
# effectively resets the cycle, but you can't do
# set_prop_cycle('color', None). So we are special-casing this.
self.set_prop_cycle(None)
else:
self.set_prop_cycle('color', clist)

def ishold(self):
"""return the HOLD status of the axes"""
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/mpl-data/stylelib/classic.mplstyle
Expand Up @@ -29,6 +29,8 @@ patch.facecolor : b
patch.edgecolor : k
patch.antialiased : True # render patches in antialiased (no jaggies)

hist.bins : 10

### FONT
#
# font properties used by text.Text. See
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/pyplot.py
Expand Up @@ -3273,7 +3273,7 @@ def step(x, y, *args, **kwargs):
@_autogen_docstring(Axes.streamplot)
def streamplot(x, y, u, v, density=1, linewidth=None, color=None, cmap=None,
norm=None, arrowsize=1, arrowstyle='-|>', minlength=0.1,
transform=None, zorder=1, start_points=None, hold=None, data=None):
transform=None, zorder=2, start_points=None, hold=None, data=None):
ax = gca()
# allow callers to override the hold state by passing hold=True|False
washold = ax.ishold()
Expand Down
19 changes: 18 additions & 1 deletion lib/matplotlib/rcsetup.py
Expand Up @@ -770,6 +770,23 @@ def validate_cycler(s):
return cycler_inst


def validate_hist_bins(s):
if isinstance(s, six.text_type) and s == 'auto':
return s
try:
return int(s)
except (TypeError, ValueError):
pass

try:
return validate_floatlist(s)
except ValueError:
pass

raise ValueError("'hist.bins' must be 'auto', an int or " +
"a sequence of floats")


# a map from key -> value, converter
defaultParams = {
'backend': ['Agg', validate_backend], # agg is certainly
Expand Down Expand Up @@ -814,7 +831,7 @@ def validate_cycler(s):
'patch.antialiased': [True, validate_bool], # antialiased (no jaggies)

## Histogram properties
'hist.bins': [10, validate_any],
'hist.bins': [10, validate_hist_bins],

## Boxplot properties
'boxplot.notch': [False, validate_bool],
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/streamplot.py
Expand Up @@ -21,7 +21,7 @@

def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
cmap=None, norm=None, arrowsize=1, arrowstyle='-|>',
minlength=0.1, transform=None, zorder=1, start_points=None):
minlength=0.1, transform=None, zorder=2, start_points=None):
"""Draws streamlines of a vector flow.
*x*, *y* : 1d arrays
Expand Down
26 changes: 26 additions & 0 deletions lib/matplotlib/tests/test_cycles.py
@@ -1,3 +1,5 @@
import warnings

from matplotlib.testing.decorators import image_comparison, cleanup
import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -147,6 +149,30 @@ def test_valid_input_forms():
assert True


@cleanup
def test_cycle_reset():
fig, ax = plt.subplots()

# Can't really test a reset because only a cycle object is stored
# but we can test the first item of the cycle.
prop = next(ax._get_lines.prop_cycler)
ax.set_prop_cycle(linewidth=[10, 9, 4])
assert prop != next(ax._get_lines.prop_cycler)
ax.set_prop_cycle(None)
got = next(ax._get_lines.prop_cycler)
assert prop == got, "expected %s, got %s" % (prop, got)

fig, ax = plt.subplots()
# Need to double-check the old set/get_color_cycle(), too
with warnings.catch_warnings():
prop = next(ax._get_lines.prop_cycler)
ax.set_color_cycle(['c', 'm', 'y', 'k'])
assert prop != next(ax._get_lines.prop_cycler)
ax.set_color_cycle(None)
got = next(ax._get_lines.prop_cycler)
assert prop == got, "expected %s, got %s" % (prop, got)


@cleanup
def test_invalid_input_forms():
fig, ax = plt.subplots()
Expand Down
3 changes: 3 additions & 0 deletions lib/matplotlib/tests/test_pickle.py
Expand Up @@ -279,6 +279,9 @@ def test_transform():
assert_equal(obj.wrapper._child, obj.composite)
# Check child -> parent links of TransformWrapper.
assert_equal(list(obj.wrapper._parents.values()), [obj.composite2])
# Check input and output dimensions are set as expected.
assert_equal(obj.wrapper.input_dims, obj.composite.input_dims)
assert_equal(obj.wrapper.output_dims, obj.composite.output_dims)


if __name__ == '__main__':
Expand Down
15 changes: 13 additions & 2 deletions lib/matplotlib/tests/test_rcparams.py
Expand Up @@ -27,7 +27,8 @@
validate_nseq_int,
validate_nseq_float,
validate_cycler,
validate_hatch)
validate_hatch,
validate_hist_bins)


mpl.rc('text', usetex=False)
Expand Down Expand Up @@ -363,7 +364,17 @@ def test_validators():
),
'fail': (('fish', ValueError),
),
}
},
{'validator': validate_hist_bins,
'success': (('auto', 'auto'),
('10', 10),
('1, 2, 3', [1, 2, 3]),
([1, 2, 3], [1, 2, 3]),
(np.arange(15), np.arange(15))
),
'fail': (('aardvark', ValueError),
)
}
)

for validator_dict in validation_tests:
Expand Down
9 changes: 8 additions & 1 deletion lib/matplotlib/transforms.py
Expand Up @@ -1552,17 +1552,24 @@ def __eq__(self, other):
def __str__(self):
return str(self._child)

# NOTE: Transform.__[gs]etstate__ should be sufficient when using only
# Python 3.4+.
def __getstate__(self):
# only store the child and parents
# only store the child information and parents
return {
'child': self._child,
'input_dims': self.input_dims,
'output_dims': self.output_dims,
# turn the weakkey dictionary into a normal dictionary
'parents': dict(six.iteritems(self._parents))
}

def __setstate__(self, state):
# re-initialise the TransformWrapper with the state's child
self._init(state['child'])
# The child may not be unpickled yet, so restore its information.
self.input_dims = state['input_dims']
self.output_dims = state['output_dims']
# turn the normal dictionary back into a WeakValueDictionary
self._parents = WeakValueDictionary(state['parents'])

Expand Down

0 comments on commit f420992

Please sign in to comment.