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

Skip to content

Commit 5d628a6

Browse files
committed
minor tweaks on axes_grid1 to improve the usability
svn path=/trunk/matplotlib/; revision=8246
1 parent a5e67b9 commit 5d628a6

5 files changed

Lines changed: 41 additions & 7 deletions

File tree

lib/mpl_toolkits/axes_grid1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
make_axes_locatable
44
from axes_grid import Grid, ImageGrid, AxesGrid
55
#from axes_divider import make_axes_locatable
6+
7+
from parasite_axes import host_subplot, host_axes

lib/mpl_toolkits/axes_grid1/axes_divider.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,8 @@ def new_vertical(self, size, pad=None, pack_start=False, **kwargs):
501501
return ax
502502

503503

504-
def append_axes(self, position, size, pad=None, **kwargs):
504+
def append_axes(self, position, size, pad=None, add_to_figure=True,
505+
**kwargs):
505506
"""
506507
create an axes at the given *position* with the same height
507508
(or width) of the main axes.
@@ -523,7 +524,8 @@ def append_axes(self, position, size, pad=None, **kwargs):
523524
else:
524525
raise ValueError("the position must be one of left, right, bottom, or top")
525526

526-
self._fig.add_axes(ax)
527+
if add_to_figure:
528+
self._fig.add_axes(ax)
527529
return ax
528530

529531
def get_aspect(self):

lib/mpl_toolkits/axes_grid1/parasite_axes.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,11 +505,30 @@ def _get_base_axes_attr(self, attrname):
505505
return new_class
506506

507507
def host_subplot_class_factory(axes_class):
508-
host_axes = host_axes_class_factory(axes_class=Axes)
509-
subplot_host = subplot_class_factory(HostAxes)
510-
return subplot_host
508+
host_axes_class = host_axes_class_factory(axes_class=axes_class)
509+
subplot_host_class = subplot_class_factory(host_axes_class)
510+
return subplot_host_class
511511

512512
HostAxes = host_axes_class_factory(axes_class=Axes)
513513
SubplotHost = subplot_class_factory(HostAxes)
514514

515515

516+
def host_axes(*args, **kwargs):
517+
import matplotlib.pyplot as plt
518+
axes_class = kwargs.pop("axes_class", None)
519+
host_axes_class = host_axes_class_factory(axes_class)
520+
fig = plt.gcf()
521+
ax = host_axes_class(fig, *args, **kwargs)
522+
fig.add_axes(ax)
523+
plt.draw_if_interactive()
524+
return ax
525+
526+
def host_subplot(*args, **kwargs):
527+
import matplotlib.pyplot as plt
528+
axes_class = kwargs.pop("axes_class", None)
529+
host_subplot_class = host_subplot_class_factory(axes_class)
530+
fig = plt.gcf()
531+
ax = host_subplot_class(fig, *args, **kwargs)
532+
fig.add_subplot(ax)
533+
plt.draw_if_interactive()
534+
return ax

lib/mpl_toolkits/axisartist/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919

2020
SubplotHost = subplot_class_factory(HostAxes)
2121

22+

lib/mpl_toolkits/axisartist/axislines.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ def new_fixed_axis(self, loc,
459459
offset=None,
460460
axes=None,
461461
):
462-
462+
463463
if axes is None:
464464
warnings.warn("'new_fixed_axis' explicitly requires the axes keyword.")
465465
axes = self.axes
@@ -697,6 +697,17 @@ def invalidate_grid_helper(self):
697697
self._grid_helper.invalidate()
698698

699699

700+
def new_fixed_axis(self, loc, offset=None):
701+
gh = self.get_grid_helper()
702+
axis = gh.new_fixed_axis(loc,
703+
nth_coord=None,
704+
axis_direction=None,
705+
offset=offset,
706+
axes=self,
707+
)
708+
return axis
709+
710+
700711
def new_floating_axis(self, nth_coord, value,
701712
axis_direction="bottom",
702713
):
@@ -758,7 +769,6 @@ def get_tightbbox(self, renderer):
758769

759770
Subplot = maxes.subplot_class_factory(Axes)
760771

761-
762772
class AxesZero(Axes):
763773
def __init__(self, *kl, **kw):
764774

0 commit comments

Comments
 (0)