axislines.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. """
  2. Axislines includes modified implementation of the Axes class. The
  3. biggest difference is that the artists responsible for drawing the axis spine,
  4. ticks, ticklabels and axis labels are separated out from mpl's Axis
  5. class. Originally, this change was motivated to support curvilinear
  6. grid. Here are a few reasons that I came up with a new axes class:
  7. * "top" and "bottom" x-axis (or "left" and "right" y-axis) can have
  8. different ticks (tick locations and labels). This is not possible
  9. with the current mpl, although some twin axes trick can help.
  10. * Curvilinear grid.
  11. * angled ticks.
  12. In the new axes class, xaxis and yaxis is set to not visible by
  13. default, and new set of artist (AxisArtist) are defined to draw axis
  14. line, ticks, ticklabels and axis label. Axes.axis attribute serves as
  15. a dictionary of these artists, i.e., ax.axis["left"] is a AxisArtist
  16. instance responsible to draw left y-axis. The default Axes.axis contains
  17. "bottom", "left", "top" and "right".
  18. AxisArtist can be considered as a container artist and
  19. has following children artists which will draw ticks, labels, etc.
  20. * line
  21. * major_ticks, major_ticklabels
  22. * minor_ticks, minor_ticklabels
  23. * offsetText
  24. * label
  25. Note that these are separate artists from Axis class of the
  26. original mpl, thus most of tick-related command in the original mpl
  27. won't work, although some effort has made to work with. For example,
  28. color and markerwidth of the ax.axis["bottom"].major_ticks will follow
  29. those of Axes.xaxis unless explicitly specified.
  30. In addition to AxisArtist, the Axes will have *gridlines* attribute,
  31. which obviously draws grid lines. The gridlines needs to be separated
  32. from the axis as some gridlines can never pass any axis.
  33. """
  34. from __future__ import (absolute_import, division, print_function,
  35. unicode_literals)
  36. import six
  37. import warnings
  38. import numpy as np
  39. from matplotlib import rcParams
  40. import matplotlib.artist as martist
  41. import matplotlib.axes as maxes
  42. from matplotlib.path import Path
  43. from matplotlib.transforms import Bbox
  44. from .axisline_style import AxislineStyle
  45. from .axis_artist import AxisArtist, GridlinesCollection
  46. class AxisArtistHelper(object):
  47. """
  48. AxisArtistHelper should define
  49. following method with given APIs. Note that the first axes argument
  50. will be axes attribute of the caller artist.::
  51. # LINE (spinal line?)
  52. def get_line(self, axes):
  53. # path : Path
  54. return path
  55. def get_line_transform(self, axes):
  56. # ...
  57. # trans : transform
  58. return trans
  59. # LABEL
  60. def get_label_pos(self, axes):
  61. # x, y : position
  62. return (x, y), trans
  63. def get_label_offset_transform(self, \
  64. axes,
  65. pad_points, fontprops, renderer,
  66. bboxes,
  67. ):
  68. # va : vertical alignment
  69. # ha : horizontal alignment
  70. # a : angle
  71. return trans, va, ha, a
  72. # TICK
  73. def get_tick_transform(self, axes):
  74. return trans
  75. def get_tick_iterators(self, axes):
  76. # iter : iterable object that yields (c, angle, l) where
  77. # c, angle, l is position, tick angle, and label
  78. return iter_major, iter_minor
  79. """
  80. class _Base(object):
  81. """
  82. Base class for axis helper.
  83. """
  84. def __init__(self):
  85. """
  86. """
  87. self.delta1, self.delta2 = 0.00001, 0.00001
  88. def update_lim(self, axes):
  89. pass
  90. class Fixed(_Base):
  91. """
  92. Helper class for a fixed (in the axes coordinate) axis.
  93. """
  94. _default_passthru_pt = dict(left=(0, 0),
  95. right=(1, 0),
  96. bottom=(0, 0),
  97. top=(0, 1))
  98. def __init__(self,
  99. loc, nth_coord=None,
  100. ):
  101. """
  102. nth_coord = along which coordinate value varies
  103. in 2d, nth_coord = 0 -> x axis, nth_coord = 1 -> y axis
  104. """
  105. self._loc = loc
  106. if loc not in ["left", "right", "bottom", "top"]:
  107. raise ValueError("%s" % loc)
  108. if nth_coord is None:
  109. if loc in ["left", "right"]:
  110. nth_coord = 1
  111. elif loc in ["bottom", "top"]:
  112. nth_coord = 0
  113. self.nth_coord = nth_coord
  114. super(AxisArtistHelper.Fixed, self).__init__()
  115. self.passthru_pt = self._default_passthru_pt[loc]
  116. _verts = np.array([[0., 0.],
  117. [1., 1.]])
  118. fixed_coord = 1-nth_coord
  119. _verts[:,fixed_coord] = self.passthru_pt[fixed_coord]
  120. # axis line in transAxes
  121. self._path = Path(_verts)
  122. def get_nth_coord(self):
  123. return self.nth_coord
  124. # LINE
  125. def get_line(self, axes):
  126. return self._path
  127. def get_line_transform(self, axes):
  128. return axes.transAxes
  129. # LABEL
  130. def get_axislabel_transform(self, axes):
  131. return axes.transAxes
  132. def get_axislabel_pos_angle(self, axes):
  133. """
  134. label reference position in transAxes.
  135. get_label_transform() returns a transform of (transAxes+offset)
  136. """
  137. loc = self._loc
  138. pos, angle_tangent = dict(left=((0., 0.5), 90),
  139. right=((1., 0.5), 90),
  140. bottom=((0.5, 0.), 0),
  141. top=((0.5, 1.), 0))[loc]
  142. return pos, angle_tangent
  143. # TICK
  144. def get_tick_transform(self, axes):
  145. trans_tick = [axes.get_xaxis_transform(),
  146. axes.get_yaxis_transform()][self.nth_coord]
  147. return trans_tick
  148. class Floating(_Base):
  149. def __init__(self, nth_coord,
  150. value):
  151. self.nth_coord = nth_coord
  152. self._value = value
  153. super(AxisArtistHelper.Floating,
  154. self).__init__()
  155. def get_nth_coord(self):
  156. return self.nth_coord
  157. def get_line(self, axes):
  158. raise RuntimeError("get_line method should be defined by the derived class")
  159. class AxisArtistHelperRectlinear(object):
  160. class Fixed(AxisArtistHelper.Fixed):
  161. def __init__(self, axes, loc, nth_coord=None):
  162. """
  163. nth_coord = along which coordinate value varies
  164. in 2d, nth_coord = 0 -> x axis, nth_coord = 1 -> y axis
  165. """
  166. super(AxisArtistHelperRectlinear.Fixed, self).__init__(
  167. loc, nth_coord)
  168. self.axis = [axes.xaxis, axes.yaxis][self.nth_coord]
  169. # TICK
  170. def get_tick_iterators(self, axes):
  171. """tick_loc, tick_angle, tick_label"""
  172. loc = self._loc
  173. if loc in ["bottom", "top"]:
  174. angle_normal, angle_tangent = 90, 0
  175. else:
  176. angle_normal, angle_tangent = 0, 90
  177. major = self.axis.major
  178. majorLocs = major.locator()
  179. major.formatter.set_locs(majorLocs)
  180. majorLabels = [major.formatter(val, i) for i, val in enumerate(majorLocs)]
  181. minor = self.axis.minor
  182. minorLocs = minor.locator()
  183. minor.formatter.set_locs(minorLocs)
  184. minorLabels = [minor.formatter(val, i) for i, val in enumerate(minorLocs)]
  185. trans_tick = self.get_tick_transform(axes)
  186. tr2ax = trans_tick + axes.transAxes.inverted()
  187. def _f(locs, labels):
  188. for x, l in zip(locs, labels):
  189. c = list(self.passthru_pt) # copy
  190. c[self.nth_coord] = x
  191. # check if the tick point is inside axes
  192. c2 = tr2ax.transform_point(c)
  193. #delta=0.00001
  194. if 0. -self.delta1<= c2[self.nth_coord] <= 1.+self.delta2:
  195. yield c, angle_normal, angle_tangent, l
  196. return _f(majorLocs, majorLabels), _f(minorLocs, minorLabels)
  197. class Floating(AxisArtistHelper.Floating):
  198. def __init__(self, axes, nth_coord,
  199. passingthrough_point, axis_direction="bottom"):
  200. super(AxisArtistHelperRectlinear.Floating, self).__init__(
  201. nth_coord, passingthrough_point)
  202. self._axis_direction = axis_direction
  203. self.axis = [axes.xaxis, axes.yaxis][self.nth_coord]
  204. def get_line(self, axes):
  205. _verts = np.array([[0., 0.],
  206. [1., 1.]])
  207. fixed_coord = 1-self.nth_coord
  208. trans_passingthrough_point = axes.transData + axes.transAxes.inverted()
  209. p = trans_passingthrough_point.transform_point([self._value,
  210. self._value])
  211. _verts[:,fixed_coord] = p[fixed_coord]
  212. return Path(_verts)
  213. def get_line_transform(self, axes):
  214. return axes.transAxes
  215. def get_axislabel_transform(self, axes):
  216. return axes.transAxes
  217. def get_axislabel_pos_angle(self, axes):
  218. """
  219. label reference position in transAxes.
  220. get_label_transform() returns a transform of (transAxes+offset)
  221. """
  222. loc = self._axis_direction
  223. #angle = dict(left=0,
  224. # right=0,
  225. # bottom=.5*np.pi,
  226. # top=.5*np.pi)[loc]
  227. if self.nth_coord == 0:
  228. angle = 0
  229. else:
  230. angle = 90
  231. _verts = [0.5, 0.5]
  232. fixed_coord = 1-self.nth_coord
  233. trans_passingthrough_point = axes.transData + axes.transAxes.inverted()
  234. p = trans_passingthrough_point.transform_point([self._value,
  235. self._value])
  236. _verts[fixed_coord] = p[fixed_coord]
  237. if not (0. <= _verts[fixed_coord] <= 1.):
  238. return None, None
  239. else:
  240. return _verts, angle
  241. def get_tick_transform(self, axes):
  242. return axes.transData
  243. def get_tick_iterators(self, axes):
  244. """tick_loc, tick_angle, tick_label"""
  245. loc = self._axis_direction
  246. if loc in ["bottom", "top"]:
  247. angle_normal, angle_tangent = 90, 0
  248. else:
  249. angle_normal, angle_tangent = 0, 90
  250. if self.nth_coord == 0:
  251. angle_normal, angle_tangent = 90, 0
  252. else:
  253. angle_normal, angle_tangent = 0, 90
  254. #angle = 90 - 90 * self.nth_coord
  255. major = self.axis.major
  256. majorLocs = major.locator()
  257. major.formatter.set_locs(majorLocs)
  258. majorLabels = [major.formatter(val, i) for i, val in enumerate(majorLocs)]
  259. minor = self.axis.minor
  260. minorLocs = minor.locator()
  261. minor.formatter.set_locs(minorLocs)
  262. minorLabels = [minor.formatter(val, i) for i, val in enumerate(minorLocs)]
  263. tr2ax = axes.transData + axes.transAxes.inverted()
  264. def _f(locs, labels):
  265. for x, l in zip(locs, labels):
  266. c = [self._value, self._value]
  267. c[self.nth_coord] = x
  268. c1, c2 = tr2ax.transform_point(c)
  269. if 0. <= c1 <= 1. and 0. <= c2 <= 1.:
  270. if 0. - self.delta1 <= [c1, c2][self.nth_coord] <= 1. + self.delta2:
  271. yield c, angle_normal, angle_tangent, l
  272. return _f(majorLocs, majorLabels), _f(minorLocs, minorLabels)
  273. class GridHelperBase(object):
  274. def __init__(self):
  275. self._force_update = True
  276. self._old_limits = None
  277. super(GridHelperBase, self).__init__()
  278. def update_lim(self, axes):
  279. x1, x2 = axes.get_xlim()
  280. y1, y2 = axes.get_ylim()
  281. if self._force_update or self._old_limits != (x1, x2, y1, y2):
  282. self._update(x1, x2, y1, y2)
  283. self._force_update = False
  284. self._old_limits = (x1, x2, y1, y2)
  285. def _update(self, x1, x2, y1, y2):
  286. pass
  287. def invalidate(self):
  288. self._force_update = True
  289. def valid(self):
  290. return not self._force_update
  291. def get_gridlines(self, which, axis):
  292. """
  293. Return list of grid lines as a list of paths (list of points).
  294. *which* : "major" or "minor"
  295. *axis* : "both", "x" or "y"
  296. """
  297. return []
  298. def new_gridlines(self, ax):
  299. """
  300. Create and return a new GridlineCollection instance.
  301. *which* : "major" or "minor"
  302. *axis* : "both", "x" or "y"
  303. """
  304. gridlines = GridlinesCollection(None, transform=ax.transData,
  305. colors=rcParams['grid.color'],
  306. linestyles=rcParams['grid.linestyle'],
  307. linewidths=rcParams['grid.linewidth'])
  308. ax._set_artist_props(gridlines)
  309. gridlines.set_grid_helper(self)
  310. ax.axes._set_artist_props(gridlines)
  311. # gridlines.set_clip_path(self.axes.patch)
  312. # set_clip_path need to be deferred after Axes.cla is completed.
  313. # It is done inside the cla.
  314. return gridlines
  315. class GridHelperRectlinear(GridHelperBase):
  316. def __init__(self, axes):
  317. super(GridHelperRectlinear, self).__init__()
  318. self.axes = axes
  319. def new_fixed_axis(self, loc,
  320. nth_coord=None,
  321. axis_direction=None,
  322. offset=None,
  323. axes=None,
  324. ):
  325. if axes is None:
  326. warnings.warn("'new_fixed_axis' explicitly requires the axes keyword.")
  327. axes = self.axes
  328. _helper = AxisArtistHelperRectlinear.Fixed(axes, loc, nth_coord)
  329. if axis_direction is None:
  330. axis_direction = loc
  331. axisline = AxisArtist(axes, _helper, offset=offset,
  332. axis_direction=axis_direction,
  333. )
  334. return axisline
  335. def new_floating_axis(self, nth_coord, value,
  336. axis_direction="bottom",
  337. axes=None,
  338. ):
  339. if axes is None:
  340. warnings.warn(
  341. "'new_floating_axis' explicitly requires the axes keyword.")
  342. axes = self.axes
  343. passthrough_point = (value, value)
  344. transform = axes.transData
  345. _helper = AxisArtistHelperRectlinear.Floating(
  346. axes, nth_coord, value, axis_direction)
  347. axisline = AxisArtist(axes, _helper)
  348. axisline.line.set_clip_on(True)
  349. axisline.line.set_clip_box(axisline.axes.bbox)
  350. return axisline
  351. def get_gridlines(self, which="major", axis="both"):
  352. """
  353. return list of gridline coordinates in data coordinates.
  354. *which* : "major" or "minor"
  355. *axis* : "both", "x" or "y"
  356. """
  357. gridlines = []
  358. if axis in ["both", "x"]:
  359. locs = []
  360. y1, y2 = self.axes.get_ylim()
  361. #if self.axes.xaxis._gridOnMajor:
  362. if which in ["both", "major"]:
  363. locs.extend(self.axes.xaxis.major.locator())
  364. #if self.axes.xaxis._gridOnMinor:
  365. if which in ["both", "minor"]:
  366. locs.extend(self.axes.xaxis.minor.locator())
  367. for x in locs:
  368. gridlines.append([[x, x], [y1, y2]])
  369. if axis in ["both", "y"]:
  370. x1, x2 = self.axes.get_xlim()
  371. locs = []
  372. if self.axes.yaxis._gridOnMajor:
  373. #if which in ["both", "major"]:
  374. locs.extend(self.axes.yaxis.major.locator())
  375. if self.axes.yaxis._gridOnMinor:
  376. #if which in ["both", "minor"]:
  377. locs.extend(self.axes.yaxis.minor.locator())
  378. for y in locs:
  379. gridlines.append([[x1, x2], [y, y]])
  380. return gridlines
  381. class SimpleChainedObjects(object):
  382. def __init__(self, objects):
  383. self._objects = objects
  384. def __getattr__(self, k):
  385. _a = SimpleChainedObjects([getattr(a, k) for a in self._objects])
  386. return _a
  387. def __call__(self, *kl, **kwargs):
  388. for m in self._objects:
  389. m(*kl, **kwargs)
  390. class Axes(maxes.Axes):
  391. class AxisDict(dict):
  392. def __init__(self, axes):
  393. self.axes = axes
  394. super(Axes.AxisDict, self).__init__()
  395. def __getitem__(self, k):
  396. if isinstance(k, tuple):
  397. r = SimpleChainedObjects([dict.__getitem__(self, k1) for k1 in k])
  398. return r
  399. elif isinstance(k, slice):
  400. if k.start == None and k.stop == None and k.step == None:
  401. r = SimpleChainedObjects(list(six.itervalues(self)))
  402. return r
  403. else:
  404. raise ValueError("Unsupported slice")
  405. else:
  406. return dict.__getitem__(self, k)
  407. def __call__(self, *v, **kwargs):
  408. return maxes.Axes.axis(self.axes, *v, **kwargs)
  409. def __init__(self, *kl, **kw):
  410. helper = kw.pop("grid_helper", None)
  411. self._axisline_on = True
  412. if helper:
  413. self._grid_helper = helper
  414. else:
  415. self._grid_helper = GridHelperRectlinear(self)
  416. super(Axes, self).__init__(*kl, **kw)
  417. self.toggle_axisline(True)
  418. def toggle_axisline(self, b=None):
  419. if b is None:
  420. b = not self._axisline_on
  421. if b:
  422. self._axisline_on = True
  423. for s in self.spines.values():
  424. s.set_visible(False)
  425. self.xaxis.set_visible(False)
  426. self.yaxis.set_visible(False)
  427. else:
  428. self._axisline_on = False
  429. for s in self.spines.values():
  430. s.set_visible(True)
  431. self.xaxis.set_visible(True)
  432. self.yaxis.set_visible(True)
  433. def _init_axis(self):
  434. super(Axes, self)._init_axis()
  435. def _init_axis_artists(self, axes=None):
  436. if axes is None:
  437. axes = self
  438. self._axislines = self.AxisDict(self)
  439. new_fixed_axis = self.get_grid_helper().new_fixed_axis
  440. for loc in ["bottom", "top", "left", "right"]:
  441. self._axislines[loc] = new_fixed_axis(loc=loc, axes=axes,
  442. axis_direction=loc)
  443. for axisline in [self._axislines["top"], self._axislines["right"]]:
  444. axisline.label.set_visible(False)
  445. axisline.major_ticklabels.set_visible(False)
  446. axisline.minor_ticklabels.set_visible(False)
  447. @property
  448. def axis(self):
  449. return self._axislines
  450. def new_gridlines(self, grid_helper=None):
  451. """
  452. Create and return a new GridlineCollection instance.
  453. *which* : "major" or "minor"
  454. *axis* : "both", "x" or "y"
  455. """
  456. if grid_helper is None:
  457. grid_helper = self.get_grid_helper()
  458. gridlines = grid_helper.new_gridlines(self)
  459. return gridlines
  460. def _init_gridlines(self, grid_helper=None):
  461. # It is done inside the cla.
  462. gridlines = self.new_gridlines(grid_helper)
  463. self.gridlines = gridlines
  464. def cla(self):
  465. # gridlines need to b created before cla() since cla calls grid()
  466. self._init_gridlines()
  467. super(Axes, self).cla()
  468. # the clip_path should be set after Axes.cla() since that's
  469. # when a patch is created.
  470. self.gridlines.set_clip_path(self.axes.patch)
  471. self._init_axis_artists()
  472. def get_grid_helper(self):
  473. return self._grid_helper
  474. def grid(self, b=None, which='major', axis="both", **kwargs):
  475. """
  476. Toggle the gridlines, and optionally set the properties of the lines.
  477. """
  478. # their are some discrepancy between the behavior of grid in
  479. # axes_grid and the original mpl's grid, because axes_grid
  480. # explicitly set the visibility of the gridlines.
  481. super(Axes, self).grid(b, which=which, axis=axis, **kwargs)
  482. if not self._axisline_on:
  483. return
  484. if b is None:
  485. if self.axes.xaxis._gridOnMinor or self.axes.xaxis._gridOnMajor or \
  486. self.axes.yaxis._gridOnMinor or self.axes.yaxis._gridOnMajor:
  487. b=True
  488. else:
  489. b=False
  490. self.gridlines.set_which(which)
  491. self.gridlines.set_axis(axis)
  492. self.gridlines.set_visible(b)
  493. if len(kwargs):
  494. martist.setp(self.gridlines, **kwargs)
  495. def get_children(self):
  496. if self._axisline_on:
  497. children = list(six.itervalues(self._axislines)) + [self.gridlines]
  498. else:
  499. children = []
  500. children.extend(super(Axes, self).get_children())
  501. return children
  502. def invalidate_grid_helper(self):
  503. self._grid_helper.invalidate()
  504. def new_fixed_axis(self, loc, offset=None):
  505. gh = self.get_grid_helper()
  506. axis = gh.new_fixed_axis(loc,
  507. nth_coord=None,
  508. axis_direction=None,
  509. offset=offset,
  510. axes=self,
  511. )
  512. return axis
  513. def new_floating_axis(self, nth_coord, value,
  514. axis_direction="bottom",
  515. ):
  516. gh = self.get_grid_helper()
  517. axis = gh.new_floating_axis(nth_coord, value,
  518. axis_direction=axis_direction,
  519. axes=self)
  520. return axis
  521. def draw(self, renderer, inframe=False):
  522. if not self._axisline_on:
  523. super(Axes, self).draw(renderer, inframe)
  524. return
  525. orig_artists = self.artists
  526. self.artists = self.artists + list(self._axislines.values()) + [self.gridlines]
  527. super(Axes, self).draw(renderer, inframe)
  528. self.artists = orig_artists
  529. def get_tightbbox(self, renderer, call_axes_locator=True):
  530. bb0 = super(Axes, self).get_tightbbox(renderer, call_axes_locator)
  531. if not self._axisline_on:
  532. return bb0
  533. bb = [bb0]
  534. for axisline in list(six.itervalues(self._axislines)):
  535. if not axisline.get_visible():
  536. continue
  537. bb.append(axisline.get_tightbbox(renderer))
  538. # if axisline.label.get_visible():
  539. # bb.append(axisline.label.get_window_extent(renderer))
  540. # if axisline.major_ticklabels.get_visible():
  541. # bb.extend(axisline.major_ticklabels.get_window_extents(renderer))
  542. # if axisline.minor_ticklabels.get_visible():
  543. # bb.extend(axisline.minor_ticklabels.get_window_extents(renderer))
  544. # if axisline.major_ticklabels.get_visible() or \
  545. # axisline.minor_ticklabels.get_visible():
  546. # bb.append(axisline.offsetText.get_window_extent(renderer))
  547. #bb.extend([c.get_window_extent(renderer) for c in artists \
  548. # if c.get_visible()])
  549. _bbox = Bbox.union([b for b in bb if b and (b.width!=0 or b.height!=0)])
  550. return _bbox
  551. Subplot = maxes.subplot_class_factory(Axes)
  552. class AxesZero(Axes):
  553. def __init__(self, *kl, **kw):
  554. super(AxesZero, self).__init__(*kl, **kw)
  555. def _init_axis_artists(self):
  556. super(AxesZero, self)._init_axis_artists()
  557. new_floating_axis = self._grid_helper.new_floating_axis
  558. xaxis_zero = new_floating_axis(nth_coord=0,
  559. value=0.,
  560. axis_direction="bottom",
  561. axes=self)
  562. xaxis_zero.line.set_clip_path(self.patch)
  563. xaxis_zero.set_visible(False)
  564. self._axislines["xzero"] = xaxis_zero
  565. yaxis_zero = new_floating_axis(nth_coord=1,
  566. value=0.,
  567. axis_direction="left",
  568. axes=self)
  569. yaxis_zero.line.set_clip_path(self.patch)
  570. yaxis_zero.set_visible(False)
  571. self._axislines["yzero"] = yaxis_zero
  572. SubplotZero = maxes.subplot_class_factory(AxesZero)