One symptom of this is yhat/ggpy#33, where ggplot figures have their legends cut off when using IPython's inline backend, which is implemented via print_figure(bbox_inches='tight').
Sorry for not looking at this sooner @minrk.
I extended the bbox_inches functionality a couple of months ago to handle every single artist that lives on the figure and the axes, so was really surprised to see this come up. Turns out that the problem is that the AnchoredOffsetbox artist claims to be clipping itself to a bbox which it isn't (i.e. the artist has been poorly implemented):
In [1]: import matplotlib.pyplot as plt
In [2]: from matplotlib.offsetbox import AnchoredOffsetbox, TextArea
In [3]:
In [3]: ax = plt.gca()
In [4]: ax.plot([0,1])
Out[4]: [<matplotlib.lines.Line2D at 0x32f12d0>]
In [5]: anchored_box = AnchoredOffsetbox(
...: loc=6,
...: child=TextArea("hello"),
...: frameon=True,
...: bbox_to_anchor=(1, 0.8),
...: bbox_transform=ax.transAxes)#
In [6]: anchored_box.set_clip_on(False)
In [7]: ax.add_artist(anchored_box)
Out[7]: <matplotlib.offsetbox.AnchoredOffsetbox at 0x32f5110>
In [8]:
In [8]: plt.draw()
In [9]: print anchored_box.get_window_extent(plt.gcf().canvas.renderer).get_points()
[[ 584. 341.8 ]
[ 627.190625 368.6 ]]
In [10]: print anchored_box.get_clip_on()
False
In [11]: print anchored_box.get_clip_box().get_points()
[[ 80. 48.]
[ 576. 432.]]
In [12]: anchored_box.set_clip_on(True)
In [13]: print anchored_box.get_window_extent(plt.gcf().canvas.renderer).get_points()
[[ 584. 341.8 ]
[ 627.190625 368.6 ]]
In this case In [13] should be restricted to the clipping bounding box, but isn't.
As a workaround, simply turning clipping off on this artist (i.e. anchored_box.set_clip_on(False)) fixes the issue. I've also submitted a PR which fixes this by default #2689.
Activity
minrk commented on Oct 18, 2013
One symptom of this is yhat/ggpy#33, where ggplot figures have their legends cut off when using IPython's inline backend, which is implemented via print_figure(bbox_inches='tight').
pelson commented on Dec 19, 2013
Sorry for not looking at this sooner @minrk.
I extended the bbox_inches functionality a couple of months ago to handle every single artist that lives on the figure and the axes, so was really surprised to see this come up. Turns out that the problem is that the AnchoredOffsetbox artist claims to be clipping itself to a bbox which it isn't (i.e. the artist has been poorly implemented):
In [1]: import matplotlib.pyplot as plt In [2]: from matplotlib.offsetbox import AnchoredOffsetbox, TextArea In [3]: In [3]: ax = plt.gca() In [4]: ax.plot([0,1]) Out[4]: [<matplotlib.lines.Line2D at 0x32f12d0>] In [5]: anchored_box = AnchoredOffsetbox( ...: loc=6, ...: child=TextArea("hello"), ...: frameon=True, ...: bbox_to_anchor=(1, 0.8), ...: bbox_transform=ax.transAxes)# In [6]: anchored_box.set_clip_on(False) In [7]: ax.add_artist(anchored_box) Out[7]: <matplotlib.offsetbox.AnchoredOffsetbox at 0x32f5110> In [8]: In [8]: plt.draw() In [9]: print anchored_box.get_window_extent(plt.gcf().canvas.renderer).get_points() [[ 584. 341.8 ] [ 627.190625 368.6 ]] In [10]: print anchored_box.get_clip_on() False In [11]: print anchored_box.get_clip_box().get_points() [[ 80. 48.] [ 576. 432.]] In [12]: anchored_box.set_clip_on(True) In [13]: print anchored_box.get_window_extent(plt.gcf().canvas.renderer).get_points() [[ 584. 341.8 ] [ 627.190625 368.6 ]]In this case In [13] should be restricted to the clipping bounding box, but isn't.
As a workaround, simply turning clipping off on this artist (i.e. anchored_box.set_clip_on(False)) fixes the issue. I've also submitted a PR which fixes this by default #2689.
FIX: Make legends show up in ipyton notebook
FIX: Make legends show up in ipyton notebook