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

Skip to content

Commit fc40214

Browse files
committed
added state to legend toggle
svn path=/trunk/matplotlib/; revision=8101
1 parent b6147e3 commit fc40214

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2010-01-29 Added draggable method to Legend to allow mouse drag
2+
placement. Thanks Adam Fraser. JDH
3+
14
2010-01-25 Fixed a bug reported by Olle Engdegard, when using
25
histograms with stepfilled and log=True - MM
36

lib/matplotlib/legend.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -935,16 +935,32 @@ def _find_best_position(self, width, height, renderer, consider=None):
935935
return ox, oy
936936

937937

938-
def draggable(self):
938+
def draggable(self, state=None):
939939
"""
940-
toggle the draggable state; if on, you can drag the legend on
941-
the canvas. The DraggableLegend helper class is returned
940+
Set the draggable state -- if state is
941+
942+
* None : toggle the current state
943+
944+
* True : turn draggable on
945+
946+
* False : turn draggable off
947+
948+
If draggable is on, you can drag the legend on the canvas with
949+
the mouse. The DraggableLegend helper instance is returned if
950+
draggable is on.
942951
"""
943-
if self._draggable is not None:
944-
self._draggable.disconnect()
945-
self._draggable = None
952+
is_draggable = self._draggable is not None
953+
954+
# if state is None we'll toggle
955+
if state is None:
956+
state = not is_draggable
957+
958+
if state:
959+
if self._draggable is None:
960+
self._draggable = DraggableLegend(self)
946961
else:
947-
948-
self._draggable = DraggableLegend(self)
962+
if self._draggable is not None:
963+
self._draggable.disconnect()
964+
self._draggable = None
949965

950966
return self._draggable

0 commit comments

Comments
 (0)