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

Skip to content

Commit 3d3a23e

Browse files
committed
Merge remote-tracking branch 'upstream/v1.3.x'
Conflicts: lib/matplotlib/axes/_axes.py lib/matplotlib/dates.py lib/mpl_toolkits/axes_grid1/axes_grid.py
2 parents 3182fa7 + 45f5c45 commit 3d3a23e

File tree

8 files changed

+138
-52
lines changed

8 files changed

+138
-52
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import matplotlib.pyplot as plt
2+
3+
from mpl_toolkits.axes_grid1 import ImageGrid
4+
fig = plt.figure(1)
5+
6+
grid1 = ImageGrid(fig, 121, (2,2), axes_pad=0.1,
7+
aspect=True, share_all=True)
8+
9+
for i in [0, 1]:
10+
grid1[i].set_aspect(2)
11+
12+
13+
grid2 = ImageGrid(fig, 122, (2,2), axes_pad=0.1,
14+
aspect=True, share_all=True)
15+
16+
17+
for i in [1, 3]:
18+
grid2[i].set_aspect(2)
19+
20+
plt.show()

lib/matplotlib/__init__.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,12 @@ def _get_xdg_config_dir():
535535
base directory spec
536536
<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
537537
"""
538-
home = get_home()
539-
if home is None:
540-
return None
541-
else:
542-
return os.environ.get('XDG_CONFIG_HOME', os.path.join(home, '.config'))
538+
path = os.environ.get('XDG_CONFIG_HOME')
539+
if path is None:
540+
path = get_home()
541+
if path is not None:
542+
path = os.path.join(path, '.config')
543+
return path
543544

544545

545546
def _get_xdg_cache_dir():
@@ -548,11 +549,12 @@ def _get_xdg_cache_dir():
548549
base directory spec
549550
<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
550551
"""
551-
home = get_home()
552-
if home is None:
553-
return None
554-
else:
555-
return os.environ.get('XDG_CACHE_HOME', os.path.join(home, '.cache'))
552+
path = os.environ.get('XDG_CACHE_HOME')
553+
if path is None:
554+
path = get_home()
555+
if path is not None:
556+
path = os.path.join(path, '.cache')
557+
return path
556558

557559

558560
def _get_config_or_cache_dir(xdg_base):
@@ -572,9 +574,8 @@ def _get_config_or_cache_dir(xdg_base):
572574
h = get_home()
573575
if h is not None:
574576
p = os.path.join(h, '.matplotlib')
575-
if (sys.platform.startswith('linux') and
576-
xdg_base is not None):
577-
p = os.path.join(xdg_base, 'matplotlib')
577+
if (sys.platform.startswith('linux') and xdg_base):
578+
p = os.path.join(xdg_base, 'matplotlib')
578579

579580
if p is not None:
580581
if os.path.exists(p):

lib/matplotlib/axes/_axes.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5169,6 +5169,17 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
51695169
if histtype == 'barstacked' and not stacked:
51705170
stacked = True
51715171

5172+
# Check whether bins or range are given explicitly.
5173+
binsgiven = (cbook.iterable(bins) or bin_range is not None)
5174+
5175+
# basic input validation
5176+
flat = np.ravel(x)
5177+
if len(flat) == 0:
5178+
raise ValueError("x must have at least one data point")
5179+
elif len(flat) == 1 and not binsgiven:
5180+
raise ValueError(
5181+
"x has only one data point. bins or range kwarg must be given")
5182+
51725183
# Massage 'x' for processing.
51735184
# NOTE: Be sure any changes here is also done below to 'weights'
51745185
if isinstance(x, np.ndarray) or not iterable(x[0]):
@@ -5223,19 +5234,16 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
52235234
# Save the datalimits for the same reason:
52245235
_saved_bounds = self.dataLim.bounds
52255236

5226-
# Check whether bins or range are given explicitly. In that
5227-
# case use those values for autoscaling.
5228-
binsgiven = (cbook.iterable(bins) or bin_range is not None)
5229-
52305237
# If bins are not specified either explicitly or via range,
52315238
# we need to figure out the range required for all datasets,
52325239
# and supply that to np.histogram.
52335240
if not binsgiven:
52345241
xmin = np.inf
52355242
xmax = -np.inf
52365243
for xi in x:
5237-
xmin = min(xmin, xi.min())
5238-
xmax = max(xmax, xi.max())
5244+
if len(xi) > 0:
5245+
xmin = min(xmin, xi.min())
5246+
xmax = max(xmax, xi.max())
52395247
bin_range = (xmin, xmax)
52405248

52415249
#hist_kwargs = dict(range=range, normed=bool(normed))
@@ -5430,15 +5438,17 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
54305438
xmin0 = max(_saved_bounds[0]*0.9, minimum)
54315439
xmax = self.dataLim.intervalx[1]
54325440
for m in n:
5433-
xmin = np.amin(m[m != 0]) # filter out the 0 height bins
5441+
if np.sum(m) > 0: # make sure there are counts
5442+
xmin = np.amin(m[m != 0]) # filter out the 0 height bins
54345443
xmin = max(xmin*0.9, minimum)
54355444
xmin = min(xmin0, xmin)
54365445
self.dataLim.intervalx = (xmin, xmax)
54375446
elif orientation == 'vertical':
54385447
ymin0 = max(_saved_bounds[1]*0.9, minimum)
54395448
ymax = self.dataLim.intervaly[1]
54405449
for m in n:
5441-
ymin = np.amin(m[m != 0]) # filter out the 0 height bins
5450+
if np.sum(m) > 0: # make sure there are counts
5451+
ymin = np.amin(m[m != 0]) # filter out the 0 height bins
54425452
ymin = max(ymin*0.9, minimum)
54435453
ymin = min(ymin0, ymin)
54445454
self.dataLim.intervaly = (ymin, ymax)

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -457,15 +457,20 @@ def _get_key(self, event):
457457
# In general, the modifier key is excluded from the modifier flag,
458458
# however this is not the case on "darwin", so double check that
459459
# we aren't adding repeat modifier flags to a modifier key.
460-
modifiers = [(6, 'super', 'super'),
461-
(3, 'alt', 'alt'),
462-
(2, 'ctrl', 'control'),
463-
]
464-
if sys.platform == 'darwin':
460+
if sys.platform == 'win32':
461+
modifiers = [(17, 'alt', 'alt'),
462+
(2, 'ctrl', 'control'),
463+
]
464+
elif sys.platform == 'darwin':
465465
modifiers = [(3, 'super', 'super'),
466466
(4, 'alt', 'alt'),
467467
(2, 'ctrl', 'control'),
468-
]
468+
]
469+
else:
470+
modifiers = [(6, 'super', 'super'),
471+
(3, 'alt', 'alt'),
472+
(2, 'ctrl', 'control'),
473+
]
469474

470475
if key is not None:
471476
# note, shift is not added to the keys as this is already accounted for

lib/matplotlib/dates.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,16 +265,25 @@ def __call__(self, s):
265265
_dateutil_parser_parse_np_vectorized = np.vectorize(dateutil.parser.parse)
266266

267267

268-
def datestr2num(d):
268+
def datestr2num(d, default=None):
269269
"""
270270
Convert a date string to a datenum using
271-
:func:`dateutil.parser.parse`. *d* can be a single string or a
272-
sequence of strings.
271+
:func:`dateutil.parser.parse`.
272+
273+
Parameters
274+
----------
275+
d : string or sequence of strings
276+
The dates to convert.
277+
278+
default : datetime instance
279+
The default date to use when fields are missing in `d`.
273280
"""
274281
if cbook.is_string_like(d):
275-
dt = dateutil.parser.parse(d)
282+
dt = dateutil.parser.parse(d, default=default)
276283
return date2num(dt)
277284
else:
285+
if default is not None:
286+
d = [dateutil.parser.parse(s, default=default) for s in d]
278287
d = np.asarray(d)
279288
if not d.size:
280289
return d

lib/matplotlib/tests/test_axes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,12 @@ def test_hist_stacked_bar():
12271227
ax.hist(d, bins=10, histtype='barstacked', align='mid', color=colors, label=labels)
12281228
ax.legend(loc='upper right', bbox_to_anchor = (1.0, 1.0), ncol=1)
12291229

1230+
@cleanup
1231+
def test_hist_emptydata():
1232+
fig = plt.figure()
1233+
ax = fig.add_subplot(111)
1234+
ax.hist([[], range(10), range(10)], histtype="step")
1235+
12301236
@image_comparison(baseline_images=['transparent_markers'], remove_text=True)
12311237
def test_transparent_markers():
12321238
np.random.seed(0)

lib/mpl_toolkits/axes_grid1/axes_grid.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -572,28 +572,31 @@ def __init__(self, fig,
572572
col, row = self._get_col_row(i)
573573

574574
if share_all:
575-
sharex = self._refax
576-
sharey = self._refax
575+
if self.axes_all:
576+
sharex = self.axes_all[0]
577+
sharey = self.axes_all[0]
578+
else:
579+
sharex = None
580+
sharey = None
577581
else:
578582
sharex = self._column_refax[col]
579583
sharey = self._row_refax[row]
580584

581585
ax = axes_class(fig, rect, sharex=sharex, sharey=sharey,
582586
**axes_class_args)
583587

584-
if share_all:
585-
if self._refax is None:
586-
self._refax = ax
587-
else:
588-
if sharex is None:
589-
self._column_refax[col] = ax
590-
if sharey is None:
591-
self._row_refax[row] = ax
592-
593588
self.axes_all.append(ax)
594589
self.axes_column[col].append(ax)
595590
self.axes_row[row].append(ax)
596591

592+
if share_all:
593+
if self._refax is None:
594+
self._refax = ax
595+
if sharex is None:
596+
self._column_refax[col] = ax
597+
if sharey is None:
598+
self._row_refax[row] = ax
599+
597600
cax = self._defaultCbarAxesClass(fig, rect,
598601
orientation=self._colorbar_location)
599602
self.cbar_axes.append(cax)
@@ -642,14 +645,15 @@ def _update_locators(self):
642645
self.cbar_axes[0].set_axes_locator(locator)
643646
self.cbar_axes[0].set_visible(True)
644647

645-
for col, ax in enumerate(self._column_refax):
648+
for col, ax in enumerate(self.axes_row[0]):
646649
if h:
647650
h.append(self._horiz_pad_size) # Size.Fixed(self._axes_pad))
648651

649652
if ax:
650-
sz = Size.AxesX(ax)
653+
sz = Size.AxesX(ax, aspect="axes", ref_ax=self.axes_all[0])
651654
else:
652-
sz = Size.AxesX(self.axes_llc)
655+
sz = Size.AxesX(self.axes_all[0],
656+
aspect="axes", ref_ax=self.axes_all[0])
653657

654658
if (self._colorbar_mode == "each" or
655659
(self._colorbar_mode == 'edge' and
@@ -672,14 +676,15 @@ def _update_locators(self):
672676

673677
v_ax_pos = []
674678
v_cb_pos = []
675-
for row, ax in enumerate(self._row_refax[::-1]):
679+
for row, ax in enumerate(self.axes_column[0][::-1]):
676680
if v:
677681
v.append(self._horiz_pad_size) # Size.Fixed(self._axes_pad))
678682

679683
if ax:
680-
sz = Size.AxesY(ax)
684+
sz = Size.AxesY(ax, aspect="axes", ref_ax=self.axes_all[0])
681685
else:
682-
sz = Size.AxesY(self.axes_llc)
686+
sz = Size.AxesY(self.axes_all[0],
687+
aspect="axes", ref_ax=self.axes_all[0])
683688

684689
if (self._colorbar_mode == "each" or
685690
(self._colorbar_mode == 'edge' and

lib/mpl_toolkits/axes_grid1/axes_size.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,39 @@ def get_size(self, renderer):
7777

7878
Scalable=Scaled
7979

80+
def _get_axes_aspect(ax):
81+
aspect = ax.get_aspect()
82+
# when aspec is "auto", consider it as 1.
83+
if aspect in ('normal', 'auto'):
84+
aspect = 1.
85+
elif aspect == "equal":
86+
aspect = 1
87+
else:
88+
aspect = float(aspect)
89+
90+
return aspect
8091

8192
class AxesX(_Base):
8293
"""
8394
Scaled size whose relative part corresponds to the data width
8495
of the *axes* multiplied by the *aspect*.
8596
"""
86-
def __init__(self, axes, aspect=1.):
97+
def __init__(self, axes, aspect=1., ref_ax=None):
8798
self._axes = axes
8899
self._aspect = aspect
100+
if aspect == "axes" and ref_ax is None:
101+
raise ValueError("ref_ax must be set when aspect='axes'")
102+
self._ref_ax = ref_ax
89103

90104
def get_size(self, renderer):
91105
l1, l2 = self._axes.get_xlim()
92-
rel_size = abs(l2-l1)*self._aspect
106+
if self._aspect == "axes":
107+
ref_aspect = _get_axes_aspect(self._ref_ax)
108+
aspect = ref_aspect/_get_axes_aspect(self._axes)
109+
else:
110+
aspect = self._aspect
111+
112+
rel_size = abs(l2-l1)*aspect
93113
abs_size = 0.
94114
return rel_size, abs_size
95115

@@ -98,13 +118,23 @@ class AxesY(_Base):
98118
Scaled size whose relative part corresponds to the data height
99119
of the *axes* multiplied by the *aspect*.
100120
"""
101-
def __init__(self, axes, aspect=1.):
121+
def __init__(self, axes, aspect=1., ref_ax=None):
102122
self._axes = axes
103123
self._aspect = aspect
124+
if aspect == "axes" and ref_ax is None:
125+
raise ValueError("ref_ax must be set when aspect='axes'")
126+
self._ref_ax = ref_ax
104127

105128
def get_size(self, renderer):
106129
l1, l2 = self._axes.get_ylim()
107-
rel_size = abs(l2-l1)*self._aspect
130+
131+
if self._aspect == "axes":
132+
ref_aspect = _get_axes_aspect(self._ref_ax)
133+
aspect = _get_axes_aspect(self._axes)
134+
else:
135+
aspect = self._aspect
136+
137+
rel_size = abs(l2-l1)*aspect
108138
abs_size = 0.
109139
return rel_size, abs_size
110140

0 commit comments

Comments
 (0)