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

Skip to content

Commit 805ce26

Browse files
committed
Merge branch 'master' of github.com:matplotlib/matplotlib into styles_XDG_compliance
2 parents 333591d + 2b9fced commit 805ce26

File tree

10 files changed

+106
-18
lines changed

10 files changed

+106
-18
lines changed

doc/api/api_changes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ original location:
113113
does the exact same thing as `FormatStrFormatter`, but for new-style
114114
formatting strings.
115115

116+
* Deprecated `matplotlib.testing.image_util` and the only function within,
117+
`matplotlib.testing.image_util.autocontrast`. These will be removed
118+
completely in v1.5.0.
119+
116120
* The ``fmt`` argument of :meth:`~matplotlib.axes.Axes.plot_date` has been
117121
changed from ``bo`` to just ``o``, so color cycling can happen by default.
118122

lib/matplotlib/cbook.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ def new_function():
119119
120120
obj_type : str, optional
121121
The object type being deprecated.
122+
123+
Example
124+
-------
125+
# To warn of the deprecation of "matplotlib.name_of_module"
126+
warn_deprecated('1.4.0', name='matplotlib.name_of_module',
127+
obj_type='module')
128+
122129
"""
123130
message = _generate_deprecation_message(
124131
since, message, name, alternative, pending, obj_type)
@@ -129,7 +136,7 @@ def new_function():
129136
def deprecated(since, message='', name='', alternative='', pending=False,
130137
obj_type='function'):
131138
"""
132-
Used to mark a function as deprecated.
139+
Decorator to mark a function as deprecated.
133140
134141
Parameters
135142
------------
@@ -164,6 +171,13 @@ def new_function():
164171
pending : bool, optional
165172
If True, uses a PendingDeprecationWarning instead of a
166173
DeprecationWarning.
174+
175+
Example
176+
-------
177+
@deprecated('1.4.0')
178+
def the_function_to_deprecate():
179+
pass
180+
167181
"""
168182
def deprecate(func, message=message, name=name, alternative=alternative,
169183
pending=pending):

lib/matplotlib/dates.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
Matplotlib provides sophisticated date plotting capabilities, standing on the
44
shoulders of python :mod:`datetime`, the add-on modules :mod:`pytz` and
5-
:mod:`dateutils`. :class:`datetime` objects are converted to floating point
5+
:mod:`dateutil`. :class:`datetime` objects are converted to floating point
66
numbers which represent time in days since 0001-01-01 UTC, plus 1. For
77
example, 0001-01-01, 06:00 is 1.25, not 0.25. The helper functions
88
:func:`date2num`, :func:`num2date` and :func:`drange` are used to facilitate
@@ -50,6 +50,9 @@
5050
Most of the date tickers can locate single or multiple values. For
5151
example::
5252
53+
# import constants for the days of the week
54+
from matplotlib.dates import MO, TU, WE, TH, FR, SA, SU
55+
5356
# tick on mondays every week
5457
loc = WeekdayLocator(byweekday=MO, tz=tz)
5558
@@ -1028,7 +1031,8 @@ def __init__(self, byweekday=1, interval=1, tz=None):
10281031
sequence.
10291032
10301033
Elements of *byweekday* must be one of MO, TU, WE, TH, FR, SA,
1031-
SU, the constants from :mod:`dateutils.rrule`.
1034+
SU, the constants from :mod:`dateutil.rrule`, which have been
1035+
imported into the :mod:`matplotlib.dates` namespace.
10321036
10331037
*interval* specifies the number of weeks to skip. For example,
10341038
``interval=2`` plots every second week.

lib/matplotlib/finance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ def _candlestick(ax, quotes, width=0.2, colorup='k', colordown='r',
10071007

10081008
vline = Line2D(
10091009
xdata=(t, t), ydata=(low, high),
1010-
color='k',
1010+
color=color,
10111011
linewidth=0.5,
10121012
antialiased=True,
10131013
)

lib/matplotlib/pyplot.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ def subplot(*args, **kwargs):
921921

922922

923923
def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
924-
subplot_kw=None, **fig_kw):
924+
subplot_kw=None, gridspec_kw=None, **fig_kw):
925925
"""
926926
Create a figure with a set of subplots already made.
927927
@@ -981,6 +981,11 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
981981
:meth:`~matplotlib.figure.Figure.add_subplot` call used to
982982
create each subplots.
983983
984+
*gridspec_kw* : dict
985+
Dict with keywords passed to the
986+
:class:`~matplotlib.gridspec.GridSpec` constructor used to create
987+
the grid the subplots are placed on.
988+
984989
*fig_kw* : dict
985990
Dict with keywords passed to the :func:`figure` call. Note that all
986991
keywords not recognized above will be automatically included here.
@@ -1055,16 +1060,19 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
10551060
(sharey, share_values))
10561061
if subplot_kw is None:
10571062
subplot_kw = {}
1063+
if gridspec_kw is None:
1064+
gridspec_kw = {}
10581065

10591066
fig = figure(**fig_kw)
1067+
gs = GridSpec(nrows, ncols, **gridspec_kw)
10601068

10611069
# Create empty object array to hold all axes. It's easiest to make it 1-d
10621070
# so we can just append subplots upon creation, and then
10631071
nplots = nrows*ncols
10641072
axarr = np.empty(nplots, dtype=object)
10651073

10661074
# Create first subplot separately, so we can share it if requested
1067-
ax0 = fig.add_subplot(nrows, ncols, 1, **subplot_kw)
1075+
ax0 = fig.add_subplot(gs[0, 0], **subplot_kw)
10681076
#if sharex:
10691077
# subplot_kw['sharex'] = ax0
10701078
#if sharey:
@@ -1094,7 +1102,7 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
10941102
subplot_kw['sharey'] = None
10951103
else:
10961104
subplot_kw['sharey'] = axarr[sys[i]]
1097-
axarr[i] = fig.add_subplot(nrows, ncols, i + 1, **subplot_kw)
1105+
axarr[i] = fig.add_subplot(gs[i // ncols, i % ncols], **subplot_kw)
10981106

10991107
# returned axis array will be always 2-d, even if nrows=ncols=1
11001108
axarr = axarr.reshape(nrows, ncols)

lib/matplotlib/testing/image_util.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@
3737

3838
import numpy as np
3939

40-
# TODO: Vectorize this
40+
from matplotlib.cbook import deprecated, warn_deprecated
41+
42+
43+
warn_deprecated('1.4.0', name='matplotlib.testing.image_util',
44+
obj_type='module')
45+
46+
47+
@deprecated('1.4.0')
4148
def autocontrast(image, cutoff=0):
4249
"""
4350
Maximize image contrast, based on histogram. This completely

lib/matplotlib/tests/test_animation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from matplotlib import pyplot as plt
1111
from matplotlib import animation
1212
from matplotlib.testing.noseclasses import KnownFailureTest
13+
from matplotlib.testing.decorators import cleanup
1314
from matplotlib.testing.decorators import CleanupTest
1415

1516

lib/matplotlib/tests/test_ticker.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,38 @@ def test_LogLocator():
5151
assert_almost_equal(loc.tick_values(1, 100), test_value)
5252

5353

54+
def test_LogFormatterExponent():
55+
class FakeAxis(object):
56+
"""Allow Formatter to be called without having a "full" plot set up."""
57+
def get_view_interval(self):
58+
return 1, 10
59+
60+
i = np.arange(-3, 4, dtype=float)
61+
expected_result = ['-3', '-2', '-1', '0', '1', '2', '3']
62+
for base in [2, 5, 10, np.pi, np.e]:
63+
formatter = mticker.LogFormatterExponent(base=base)
64+
formatter.axis = FakeAxis()
65+
vals = base**i
66+
labels = [formatter(x, pos) for (x, pos) in zip(vals, i)]
67+
nose.tools.assert_equal(labels, expected_result)
68+
69+
# Should be a blank string for non-integer powers if labelOnlyBase=True
70+
formatter = mticker.LogFormatterExponent(base=10, labelOnlyBase=True)
71+
formatter.axis = FakeAxis()
72+
nose.tools.assert_equal(formatter(10**0.1), '')
73+
74+
# Otherwise, non-integer powers should be nicely formatted
75+
locs = np.array([0.1, 0.00001, np.pi, 0.2, -0.2, -0.00001])
76+
i = range(len(locs))
77+
expected_result = ['0.1', '1e-05', '3.14', '0.2', '-0.2', '-1e-05']
78+
for base in [2, 5, 10, np.pi, np.e]:
79+
formatter = mticker.LogFormatterExponent(base, labelOnlyBase=False)
80+
formatter.axis = FakeAxis()
81+
vals = base**locs
82+
labels = [formatter(x, pos) for (x, pos) in zip(vals, i)]
83+
nose.tools.assert_equal(labels, expected_result)
84+
85+
5486
def test_use_offset():
5587
for use_offset in [True, False]:
5688
with matplotlib.rc_context({'axes.formatter.useoffset': use_offset}):

lib/matplotlib/ticker.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -728,13 +728,10 @@ def __call__(self, x, pos=None):
728728
isDecade = is_close_to_int(fx)
729729
if not isDecade and self.labelOnlyBase:
730730
s = ''
731-
#if 0: pass
732-
elif fx > 10000:
733-
s = '%1.0e' % fx
734-
#elif x<1: s = '$10^{%d}$'%fx
735-
#elif x<1: s = '10^%d'%fx
736-
elif fx < 1:
737-
s = '%1.0e' % fx
731+
elif abs(fx) > 10000:
732+
s = '%1.0g' % fx
733+
elif abs(fx) < 1:
734+
s = '%1.0g' % fx
738735
else:
739736
s = self.pprint_val(fx, d)
740737
if sign == -1:

lib/matplotlib/widgets.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ def onselect(vmin, vmax):
10441044
"""
10451045

10461046
def __init__(self, ax, onselect, direction, minspan=None, useblit=False,
1047-
rectprops=None, onmove_callback=None):
1047+
rectprops=None, onmove_callback=None, span_stays=False):
10481048
"""
10491049
Create a span selector in *ax*. When a selection is made, clear
10501050
the span and call *onselect* with::
@@ -1062,6 +1062,9 @@ def __init__(self, ax, onselect, direction, minspan=None, useblit=False,
10621062
10631063
Set the visible attribute to *False* if you want to turn off
10641064
the functionality of the span selector
1065+
1066+
If *span_stays* is True, the span stays visble after making
1067+
a valid selection.
10651068
"""
10661069
AxesWidget.__init__(self, ax)
10671070

@@ -1081,7 +1084,8 @@ def __init__(self, ax, onselect, direction, minspan=None, useblit=False,
10811084
self.onselect = onselect
10821085
self.onmove_callback = onmove_callback
10831086
self.minspan = minspan
1084-
1087+
self.span_stays = span_stays
1088+
10851089
# Needed when dragging out of axes
10861090
self.buttonDown = False
10871091
self.prev = (0, 0)
@@ -1116,7 +1120,13 @@ def new_axes(self, ax):
11161120
transform=trans,
11171121
visible=False,
11181122
**self.rectprops)
1119-
1123+
if self.span_stays:
1124+
self.stay_rect = Rectangle((0, 0), w, h,
1125+
transform=trans,
1126+
visible=False,
1127+
**self.rectprops)
1128+
self.ax.add_patch(self.stay_rect)
1129+
11201130
if not self.useblit:
11211131
self.ax.add_patch(self.rect)
11221132

@@ -1140,6 +1150,9 @@ def press(self, event):
11401150
self.buttonDown = True
11411151

11421152
self.rect.set_visible(self.visible)
1153+
if self.span_stays:
1154+
self.stay_rect.set_visible(False)
1155+
11431156
if self.direction == 'horizontal':
11441157
self.pressv = event.xdata
11451158
else:
@@ -1155,6 +1168,14 @@ def release(self, event):
11551168
self.buttonDown = False
11561169

11571170
self.rect.set_visible(False)
1171+
1172+
if self.span_stays:
1173+
self.stay_rect.set_x(self.rect.get_x())
1174+
self.stay_rect.set_y(self.rect.get_y())
1175+
self.stay_rect.set_width(self.rect.get_width())
1176+
self.stay_rect.set_height(self.rect.get_height())
1177+
self.stay_rect.set_visible(True)
1178+
11581179
self.canvas.draw()
11591180
vmin = self.pressv
11601181
if self.direction == 'horizontal':

0 commit comments

Comments
 (0)