10000 Merge remote-tracking branch 'matplotlib/v1.5.x' into v2.x · matplotlib/matplotlib@5976e68 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5976e68

Browse files
committed
Merge remote-tracking branch 'matplotlib/v1.5.x' into v2.x
Conflicts: lib/matplotlib/axes/_axes.py - merge in c is None handling lib/matplotlib/axes/_base.py - kept v2.x version lib/matplotlib/tests/test_axes.py - kept all new tests lib/matplotlib/ticker.py - kept v2.x version, but change a math.ceil call to np.ceil
2 parents 102872a + 4f3b5cc commit 5976e68

File tree

6 files changed

+102
-25
lines changed

6 files changed

+102
-25
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3853,6 +3853,10 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
38533853
edgecolors = co
38543854
if facecolors is None:
38553855
facecolors = co
3856+
if c is not None:
3857+
raise ValueError("Supply a 'c' kwarg or a 'color' kwarg"
3858+
" but not both; they differ but"
3859+
" their functionalities overlap.")
38563860
if c is None:
38573861
if facecolors is not None:
38583862
c = facecolors
@@ -3861,6 +3865,9 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
38613865
c = 'b' # The original default
38623866
else:
38633867
c = self._get_patches_for_fill.get_next_color()
3868+
c_none = True
3869+
else:
3870+
c_none = False
38643871

38653872
if edgecolors is None and not rcParams['_internal.classic_mode']:
38663873
edgecolors = 'face'
@@ -3888,16 +3895,19 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
38883895
# c is an array for mapping. The potential ambiguity
38893896
# with a sequence of 3 or 4 numbers is resolved in
38903897
# favor of mapping, not rgb or rgba.
3891-
try:
3892-
c_array = np.asanyarray(c, dtype=float)
3893-
if c_array.size == x.size:
3894-
c = np.ma.ravel(c_array)
3895-
else:
3896-
# Wrong size; it must not be intended for mapping.
3897-
c_array = None
3898-
except ValueError:
3899-
# Failed to make a floating-point array; c must be color specs.
3898+
if c_none or co is not None:
39003899
c_array = None
3900+
else:
3901+
try:
3902+
c_array = np.asanyarray(c, dtype=float)
3903+
if c_array.size == x.size:
3904+
c = np.ma.ravel(c_array)
3905+
else:
3906+
# Wrong size; it must not be intended for mapping.
3907+
c_array = None
3908+
except ValueError:
3909+
# Failed to make a floating-point array; c must be color specs.
3910+
c_array = None
39013911

39023912
if c_array is None:
39033913
colors = c # must be acceptable as PathCollection facecolors

lib/ 8000 matplotlib/axes/_base.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,10 @@ def _setdefaults(self, defaults, *kwargs):
297297

298298
def _makeline(self, x, y, kw, kwargs):
299299
kw = kw.copy() # Don't modify the original kw.
300-
kwargs = kwargs.copy()
301-
default_dict = self._getdefaults(None, kw, kwargs)
302-
self._setdefaults(default_dict, kw, kwargs)
300+
kw.update(kwargs)
301+
default_dict = self._getdefaults(None, kw)
302+
self._setdefaults(default_dict, kw)
303303
seg = mlines.Line2D(x, y, **kw)
304-
self.set_lineprops(seg, **kwargs)
305304
return seg
306305

307306
def _makefill(self, x, y, kw, kwargs):

lib/matplotlib/backends/qt_editor/figureoptions.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,12 @@ def apply_callback(data):
120120
# Set / General
121121
title, xmin, xmax, xlabel, xscale, ymin, ymax, ylabel, yscale, \
122122
generate_legend = general
123-
axes.set_xscale(xscale)
124-
axes.set_yscale(yscale)
123+
124+
if axes.get_xscale() != xscale:
125+
axes.set_xscale(xscale)
126+
if axes.get_yscale() != yscale:
127+
axes.set_yscale(yscale)
128+
125129
axes.set_title(title)
126130
axes.set_xlim(xmin, xmax)
127131
axes.set_xlabel(xlabel)

lib/matplotlib/lines.py

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,18 @@ def __init__(self, xdata, ydata,
335335
if solid_joinstyle is None:
336336
solid_joinstyle = rcParams['lines.solid_joinstyle']
337337

338+
if is_string_like(linestyle):
339+
ds, ls = self._split_drawstyle_linestyle(linestyle)
340+
if ds is not None and drawstyle is not None and ds != drawstyle:
341+
raise ValueError("Inconsistent drawstyle ({0!r}) and "
342+
"linestyle ({1!r})".format(drawstyle,
343+
linestyle)
344+
)
345+
linestyle = ls
346+
347+
if ds is not None:
348+
drawstyle = ds
349+
338350
if drawstyle is None:
339351
drawstyle = 'default'
340352

@@ -1006,6 +1018,38 @@ def set_linewidth(self, w):
10061018
self.stale = True
10071019
self._linewidth = w
10081020

1021+
def _split_drawstyle_linestyle(self, ls):
1022+
'''Split drawstyle from linestyle string
1023+
1024+
If `ls` is only a drawstyle default to returning a linestyle
1025+
of '-'.
1026+
1027+
Parameters
1028+
----------
1029+
ls : str
1030+
The linestyle to be processed
1031+
1032+
Returns
1033+
-------
1034+
ret_ds : str or None
1035+
If the linestyle string does not contain a drawstyle prefix
1036+
return None, otherwise return it.
1037+
1038+
ls : str
1039+
The linestyle with the drawstyle (if any) stripped.
1040+
'''
1041+
ret_ds = None
1042+
for ds in self.drawStyleKeys: # long names are first in the list
1043+
if ls.startswith(ds):
1044+
ret_ds = ds
1045+
if len(ls) > len(ds):
1046+
ls = ls[len(ds):]
1047+
else:
1048+
ls = '-'
1049+
break
1050+
1051+
return ret_ds, ls
1052+
10091053
def set_linestyle(self, ls):
10101054
"""
10111055
Set the linestyle of the line (also accepts drawstyles,
@@ -1058,15 +1102,9 @@ def set_linestyle(self, ls):
10581102
self._dashOffset = ls[0]
10591103
self._linestyle = "--"
10601104
return
1061-
1062-
for ds in self.drawStyleKeys: # long names are first in the list
1063-
if ls.startswith(ds):
1064-
self.set_drawstyle(ds)
1065-
if len(ls) > len(ds):
1066-
ls = ls[len(ds):]
1067-
else:
1068-
ls = '-'
1069-
break
1105+
ds, ls = self._split_drawstyle_linestyle(ls)
1106+
if ds is not None:
1107+
self.set_drawstyle(ds)
10701108

10711109
if ls in [' ', '', 'none']:
10721110
ls = 'None'

lib/matplotlib/tests/test_axes.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4384,6 +4384,25 @@ def test_axis_set_tick_params_labelsize_labelcolor():
43844384
assert axis_1.yaxis.majorTicks[0]._labelcolor == 'red'
43854385

43864386

4387+
@cleanup
4388+
def test_none_kwargs():
4389+
fig, ax = plt.subplots()
4390+
ln, = ax.plot(range(32), linestyle=None)
4391+
assert ln.get_linestyle() == '-'
4392+
4393+
4394+
@cleanup
4395+
def test_ls_ds_conflict():
4396+
assert_raises(ValueError, plt.plot, range(32),
4397+
linestyle='steps-pre:', drawstyle='steps-post')
4398+
4399+
4400+
@cleanup
4401+
def test_ls_ds_conflict():
4402+
assert_raises(ValueError, plt.plot, range(32),
4403+
linestyle='steps-pre:', drawstyle='steps-post')
4404+
4405+
43874406
@image_comparison(baseline_images=['date_timezone_x'], extensions=['png'])
43884407
def test_date_timezone_x():
43894408
# Tests issue 5575
@@ -4456,6 +4475,13 @@ def test_axisbelow():
44564475
ax.set_axisbelow(setting)
44574476

44584477

4478+
@cleanup
4479+
def test_large_offset():
4480+
fig, ax = plt.subplots()
4481+
ax.plot((1 + np.array([0, 1.e-12])) * 1.e27)
4482+
fig.canvas.draw()
4483+
4484+
44594485
if __name__ == '__main__':
44604486
import nose
44614487
import sys

lib/matplotlib/ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ def _compute_offset(self):
666666
# equal up to that precision?
667667
# Note: Internally using oom instead of 10 ** oom avoids some numerical
668668
# accuracy issues.
669-
oom_max = math.ceil(math.log10(abs_max))
669+
oom_max = np.ceil(math.log10(abs_max))
670670
oom = 1 + next(oom for oom in itertools.count(oom_max, -1)
671671
if abs_min // 10 ** oom != abs_max // 10 ** oom)
672672
if (abs_max - abs_min) / 10 ** oom <= 1e-2:

0 commit comments

Comments
 (0)
0