|
10 | 10 | object that can be used to set the axes_locator of the axes.
|
11 | 11 | """
|
12 | 12 |
|
| 13 | +import numpy as np |
| 14 | + |
13 | 15 | from matplotlib import cbook
|
14 | 16 | from matplotlib.axes import SubplotBase
|
15 | 17 | from matplotlib.gridspec import SubplotSpec, GridSpec
|
@@ -274,10 +276,7 @@ def append_size(self, position, size):
|
274 | 276 | cbook._check_in_list(["left", "right", "bottom", "top"],
|
275 | 277 | position=position)
|
276 | 278 |
|
277 |
| - def add_auto_adjustable_area(self, |
278 |
| - use_axes, pad=0.1, |
279 |
| - adjust_dirs=None, |
280 |
| - ): |
| 279 | + def add_auto_adjustable_area(self, use_axes, pad=0.1, adjust_dirs=None): |
281 | 280 | if adjust_dirs is None:
|
282 | 281 | adjust_dirs = ["left", "right", "bottom", "top"]
|
283 | 282 | from .axes_size import Padded, SizeFromFunc, GetExtentHelper
|
@@ -362,90 +361,18 @@ def __init__(self, fig, *args, horizontal=None, vertical=None,
|
362 | 361 | *args* can be passed as a single 3-digit number (e.g. 234 for
|
363 | 362 | (2, 3, 4)).
|
364 | 363 | """
|
365 |
| - |
366 | 364 | self.figure = fig
|
367 |
| - |
368 |
| - if len(args) == 1: |
369 |
| - if isinstance(args[0], SubplotSpec): |
370 |
| - self._subplotspec = args[0] |
371 |
| - else: |
372 |
| - try: |
373 |
| - s = str(int(args[0])) |
374 |
| - rows, cols, num = map(int, s) |
375 |
| - except ValueError: |
376 |
| - raise ValueError( |
377 |
| - 'Single argument to subplot must be a 3-digit integer') |
378 |
| - self._subplotspec = GridSpec(rows, cols)[num-1] |
379 |
| - # num - 1 for converting from MATLAB to python indexing |
380 |
| - elif len(args) == 3: |
381 |
| - rows, cols, num = args |
382 |
| - rows = int(rows) |
383 |
| - cols = int(cols) |
384 |
| - if isinstance(num, tuple) and len(num) == 2: |
385 |
| - num = [int(n) for n in num] |
386 |
| - self._subplotspec = GridSpec(rows, cols)[num[0]-1:num[1]] |
387 |
| - else: |
388 |
| - self._subplotspec = GridSpec(rows, cols)[int(num)-1] |
389 |
| - # num - 1 for converting from MATLAB to python indexing |
390 |
| - else: |
391 |
| - raise ValueError(f'Illegal argument(s) to subplot: {args}') |
392 |
| - |
393 |
| - # total = rows*cols |
394 |
| - # num -= 1 # convert from matlab to python indexing |
395 |
| - # # i.e., num in range(0, total) |
396 |
| - # if num >= total: |
397 |
| - # raise ValueError( 'Subplot number exceeds total subplots') |
398 |
| - # self._rows = rows |
399 |
| - # self._cols = cols |
400 |
| - # self._num = num |
401 |
| - |
402 |
| - # self.update_params() |
403 |
| - |
404 |
| - # sets self.fixbox |
405 |
| - self.update_params() |
406 |
| - |
407 |
| - pos = self.figbox.bounds |
408 |
| - |
409 |
| - Divider.__init__(self, fig, pos, horizontal or [], vertical or [], |
| 365 | + self._subplotspec = SubplotSpec._from_subplot_args(fig, args) |
| 366 | + self.update_params() # sets self.figbox |
| 367 | + Divider.__init__(self, fig, pos=self.figbox.bounds, |
| 368 | + horizontal=horizontal or [], vertical=vertical or [], |
410 | 369 | aspect=aspect, anchor=anchor)
|
411 | 370 |
|
412 | 371 | def get_position(self):
|
413 | 372 | "return the bounds of the subplot box"
|
414 |
| - |
415 | 373 | self.update_params() # update self.figbox
|
416 | 374 | return self.figbox.bounds
|
417 | 375 |
|
418 |
| - # def update_params(self): |
419 |
| - # 'update the subplot position from fig.subplotpars' |
420 |
| - |
421 |
| - # rows = self._rows |
422 |
| - # cols = self._cols |
423 |
| - # num = self._num |
424 |
| - |
425 |
| - # pars = self.figure.subplotpars |
426 |
| - # left = pars.left |
427 |
| - # right = pars.right |
428 |
| - # bottom = pars.bottom |
429 |
| - # top = pars.top |
430 |
| - # wspace = pars.wspace |
431 |
| - # hspace = pars.hspace |
432 |
| - # totWidth = right-left |
433 |
| - # totHeight = top-bottom |
434 |
| - |
435 |
| - # figH = totHeight/(rows + hspace*(rows-1)) |
436 |
| - # sepH = hspace*figH |
437 |
| - |
438 |
| - # figW = totWidth/(cols + wspace*(cols-1)) |
439 |
| - # sepW = wspace*figW |
440 |
| - |
441 |
| - # rowNum, colNum = divmod(num, cols) |
442 |
| - |
443 |
| - # figBottom = top - (rowNum+1)*figH - rowNum*sepH |
444 |
| - # figLeft = left + colNum*(figW + sepW) |
445 |
| - |
446 |
| - # self.figbox = mtransforms.Bbox.from_bounds(figLeft, figBottom, |
447 |
| - # figW, figH) |
448 |
| - |
449 | 376 | def update_params(self):
|
450 | 377 | """Update the subplot position from fig.subplotpars."""
|
451 | 378 | self.figbox = self.get_subplotspec().get_position(self.figure)
|
@@ -664,16 +591,12 @@ def get_subplotspec(self):
|
664 | 591 |
|
665 | 592 | class HBoxDivider(SubplotDivider):
|
666 | 593 |
|
667 |
| - def __init__(self, fig, *args, **kwargs): |
668 |
| - SubplotDivider.__init__(self, fig, *args, **kwargs) |
669 |
| - |
670 | 594 | @staticmethod
|
671 | 595 | def _determine_karray(equivalent_sizes, appended_sizes,
|
672 | 596 | max_equivalent_size,
|
673 | 597 | total_appended_size):
|
674 | 598 |
|
675 | 599 | n = len(equivalent_sizes)
|
676 |
| - import numpy as np |
677 | 600 | A = np.mat(np.zeros((n+1, n+1), dtype="d"))
|
678 | 601 | B = np.zeros((n+1), dtype="d")
|
679 | 602 | # AxK = B
|
|
0 commit comments