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

Skip to content

Merge 1.5 into 2x. #6187

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 17 commits into from
Mar 19, 2016
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
10 changes: 10 additions & 0 deletions doc/api/api_changes/2016-03-13-PMH.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Changed default ``autorange`` behavior in boxplots
``````````````````````````````````````````````````

Prior to v1.5.2, the whiskers of boxplots would extend to the mininum
and maximum values if the quartiles were all equal (i.e., Q1 = median
= Q3). This behavior has been disabled by default to restore consistency
with other plotting packages.

To restore the old behavior, simply set ``autorange=True`` when
calling ``plt.boxplot``.
4 changes: 2 additions & 2 deletions lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,8 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
# Re-use the savefig DPI for ours if none is given
if dpi is None:
dpi = rcParams['savefig.dpi']
if dpi == 'figure':
dpi = self._fig.dpi
if dpi == 'figure':
dpi = self._fig.dpi

if codec is None:
codec = rcParams['animation.codec']
Expand Down
279 changes: 143 additions & 136 deletions lib/matplotlib/axes/_axes.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2141,8 +2141,8 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',

if dpi is None:
dpi = rcParams['savefig.dpi']
if dpi == 'figure':
dpi = self.figure.dpi
if dpi == 'figure':
dpi = self.figure.dpi

origDPI = self.figure.dpi
origfacecolor = self.figure.get_facecolor()
Expand Down
3 changes: 3 additions & 0 deletions lib/matplotlib/backends/backend_qt5agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ def draw_idle(self):
QtCore.QTimer.singleShot(0, self.__draw_idle_agg)

def __draw_idle_agg(self, *args):
if self.height() < 0 or self.width() < 0:
self._agg_draw_pending = False
return
try:
FigureCanvasAgg.draw(self)
self.update()
Expand Down
33 changes: 23 additions & 10 deletions lib/matplotlib/backends/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,23 @@

QT_API = None

if (QT_API_ENV is not None):
# check if any binding is already imported, if so silently ignore the
# rcparams/ENV settings and use what ever is already imported.
if 'PySide' in sys.modules:
# user has imported PySide before importing mpl
QT_API = QT_API_PYSIDE

if 'PyQt4' in sys.modules:
# user has imported PyQt4 before importing mpl
# this case also handles the PyQt4v2 case as once sip is imported
# the API versions can not be changed so do not try
QT_API = QT_API_PYQT

if 'PyQt5' in sys.modules:
# the user has imported PyQt5 before importing mpl
QT_API = QT_API_PYQT5

if (QT_API_ENV is not None) and QT_API is None:
try:
QT_ENV_MAJOR_VERSION = ETS[QT_API_ENV][1]
except KeyError:
Expand All @@ -61,15 +77,12 @@
elif rcParams['backend'] == 'Qt4Agg':
QT_API = rcParams['backend.qt4']
else:
# A different backend was specified, but we still got here because a Qt
# related file was imported. This is allowed, so lets try and guess
# what we should be using.
if "PyQt4" in sys.modules or "PySide" in sys.modules:
# PyQt4 or PySide is actually used.
QT_API = rcParams['backend.qt4']
else:
# This is a fallback: PyQt5
QT_API = rcParams['backend.qt5']
# A non-Qt backend was specified, no version of the Qt
# bindings is imported, but we still got here because a Qt
# related file was imported. This is allowed, fall back to Qt5
# using which ever binding the rparams ask for.

QT_API = rcParams['backend.qt5']

# We will define an appropriate wrapper for the differing versions
# of file dialog.
Expand Down
80 changes: 49 additions & 31 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,17 @@ def is_sequence_of_strings(obj):
return True


def is_hashable(obj):
"""
Returns true if *obj* can be hashed
"""
try:
hash(obj)
except TypeError:
return False
return True


def is_writable_file_like(obj):
'return true if *obj* looks like a file object with a *write* method'
return hasattr(obj, 'write') and six.callable(obj.write)
Expand Down Expand Up @@ -1863,39 +1874,46 @@ def delete_masked_points(*args):
return margs


def boxplot_stats(X, whis=1.5, bootstrap=None, labels=None):
'''
Returns list of dictionaries of staticists to be use to draw a series of
box and whisker plots. See the `Returns` section below to the required
keys of the dictionary. Users can skip this function and pass a user-
defined set of dictionaries to the new `axes.bxp` method instead of
relying on MPL to do the calcs.
def boxplot_stats(X, whis=1.5, bootstrap=None, labels=None,
autorange=False):
"""
Returns list of dictionaries of statistics used to draw a series
of box and whisker plots. The `Returns` section enumerates the
required keys of the dictionary. Users can skip this function and
pass a user-defined set of dictionaries to the new `axes.bxp` method
instead of relying on MPL to do the calculations.

Parameters
----------
X : array-like
Data that will be represented in the boxplots. Should have 2 or fewer
dimensions.
Data that will be represented in the boxplots. Should have 2 or
fewer dimensions.

whis : float, string, or sequence (default = 1.5)
As a float, determines the reach of the whiskers past the first and
third quartiles (e.g., Q3 + whis*IQR, QR = interquartile range, Q3-Q1).
Beyond the whiskers, data are considered outliers and are plotted as
individual points. Set this to an unreasonably high value to force the
whiskers to show the min and max data. Alternatively, set this to an
ascending sequence of percentile (e.g., [5, 95]) to set the whiskers
at specific percentiles of the data. Finally, can `whis` be the
string 'range' to force the whiskers to the min and max of the data.
In the edge case that the 25th and 75th percentiles are equivalent,
`whis` will be automatically set to 'range'

bootstrap : int or None (default)
Number of times the confidence intervals around the median should
be bootstrapped (percentile method).

labels : sequence
Labels for each dataset. Length must be compatible with dimensions
of `X`
As a float, determines the reach of the whiskers past the first
and third quartiles (e.g., Q3 + whis*IQR, QR = interquartile
range, Q3-Q1). Beyond the whiskers, data are considered outliers
and are plotted as individual points. This can be set this to an
ascending sequence of percentile (e.g., [5, 95]) to set the
whiskers at specific percentiles of the data. Finally, `whis`
can be the string ``'range'`` to force the whiskers to the
minimum and maximum of the data. In the edge case that the 25th
and 75th percentiles are equivalent, `whis` can be automatically
set to ``'range'`` via the `autorange` option.

bootstrap : int, optional
Number of times the confidence intervals around the median
should be bootstrapped (percentile method).

labels : array-like, optional
Labels for each dataset. Length must be compatible with
dimensions of `X`.

autorange : bool, optional (False)
When `True` and the data are distributed such that the 25th and
75th percentiles are equal, ``whis`` is set to ``'range'`` such
that the whisker ends are at the minimum and maximum of the
data.

Returns
-------
Expand All @@ -1920,8 +1938,8 @@ def boxplot_stats(X, whis=1.5, bootstrap=None, labels=None):

Notes
-----
Non-bootstrapping approach to confidence interval uses Gaussian-based
asymptotic approximation:
Non-bootstrapping approach to confidence interval uses Gaussian-
based asymptotic approximation:

.. math::

Expand All @@ -1931,7 +1949,7 @@ def boxplot_stats(X, whis=1.5, bootstrap=None, labels=None):
McGill, R., Tukey, J.W., and Larsen, W.A. (1978) "Variations of
Boxplots", The American Statistician, 32:12-16.

'''
"""

def _bootstrap_median(data, N=5000):
# determine 95% confidence intervals of the median
Expand Down Expand Up @@ -2011,7 +2029,7 @@ def _compute_conf_interval(data, med, iqr, bootstrap):

# interquartile range
stats['iqr'] = q3 - q1
if stats['iqr'] == 0:
if stats['iqr'] == 0 and autorange:
whis = 'range'

# conf. interval around median
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _get_value(val):
except TypeError:
if cbook.iterable(val) and len(val):
try:
float(val[0])
float(cbook.safe_first_element(val))
except (TypeError, ValueError):
pass # raise below
else:
Expand All @@ -164,7 +164,7 @@ def _get_bool(val):
if not cbook.iterable(val):
val = (val,)
try:
bool(val[0])
bool(cbook.safe_first_element(val))
except (TypeError, IndexError):
raise TypeError('val must be a bool or nonzero sequence of them')
return val
Expand Down Expand Up @@ -532,7 +532,7 @@ def set_linestyle(self, ls):
The line style.
"""
try:
if cbook.is_string_like(ls):
if cbook.is_string_like(ls) and cbook.is_hashable(ls):
ls = cbook.ls_mapper.get(ls, ls)
dashes = [mlines.get_dash_pattern(ls)]
elif cbook.iterable(ls):
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,8 @@ def __init__(self, colors, name='from_list', N=None):
if N is None:
N = len(self.colors)
else:
if cbook.is_string_like(self.colors):
if (cbook.is_string_like(self.colors) and
cbook.is_hashable(self.colors)):
self.colors = [self.colors] * N
self.monochrome = True
elif cbook.iterable(self.colors):
Expand Down
2 changes: 0 additions & 2 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1508,8 +1508,6 @@ def savefig(self, *args, **kwargs):
"""

kwargs.setdefault('dpi', rcParams['savefig.dpi'])
if kwargs['dpi'] == 'figure':
kwargs['dpi'] = self.get_dpi()
frameon = kwargs.pop('frameon', rcParams['savefig.frameon'])
transparent = kwargs.pop('transparent',
rcParams['savefig.transparent'])
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading