Skip to content

Commit 41af28d

Browse files
committed
add text_font to LengenRV and LegendHorizontal to manage different font name. Add some modification to allow matplotlib legend update when we set a new figure or when you add new line/scatter/bar in graph. Add example to manage legend update with matplotlib legend.
1 parent f83dd4e commit 41af28d

File tree

26 files changed

+3888
-1021
lines changed

26 files changed

+3888
-1021
lines changed

example_all_interactive_options/graph_widget.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class MatplotFigure(Widget):
4747
pos_y_rect_ver=NumericProperty(0)
4848
invert_rect_ver = BooleanProperty(False)
4949
invert_rect_hor = BooleanProperty(False)
50-
legend_instance = ObjectProperty(None)
50+
legend_instance = ObjectProperty(None, allownone=True)
5151
legend_do_scroll_x = BooleanProperty(True)
5252
legend_do_scroll_y = BooleanProperty(True)
5353
do_pan_x = BooleanProperty(True)
@@ -83,9 +83,16 @@ def on_figure(self, obj, value):
8383
#set default xmin/xmax and ymin/ymax
8484
self.xmin,self.xmax = self.axes.get_xlim()
8585
self.ymin,self.ymax = self.axes.get_ylim()
86-
86+
87+
if self.legend_instance:
88+
self.legend_instance.reset_legend()
89+
self.legend_instance=None
90+
8791
# Texture
8892
self._img_texture = Texture.create(size=(w, h))
93+
94+
#close last figure in memory (avoid max figure warning)
95+
matplotlib.pyplot.close()
8996

9097
def __init__(self, **kwargs):
9198
super(MatplotFigure, self).__init__(**kwargs)

example_basic/graph_widget.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class MatplotFigure(Widget):
4747
pos_y_rect_ver=NumericProperty(0)
4848
invert_rect_ver = BooleanProperty(False)
4949
invert_rect_hor = BooleanProperty(False)
50-
legend_instance = ObjectProperty(None)
50+
legend_instance = ObjectProperty(None, allownone=True)
5151
legend_do_scroll_x = BooleanProperty(True)
5252
legend_do_scroll_y = BooleanProperty(True)
5353
do_pan_x = BooleanProperty(True)
@@ -83,9 +83,16 @@ def on_figure(self, obj, value):
8383
#set default xmin/xmax and ymin/ymax
8484
self.xmin,self.xmax = self.axes.get_xlim()
8585
self.ymin,self.ymax = self.axes.get_ylim()
86-
86+
87+
if self.legend_instance:
88+
self.legend_instance.reset_legend()
89+
self.legend_instance=None
90+
8791
# Texture
8892
self._img_texture = Texture.create(size=(w, h))
93+
94+
#close last figure in memory (avoid max figure warning)
95+
matplotlib.pyplot.close()
8996

9097
def __init__(self, **kwargs):
9198
super(MatplotFigure, self).__init__(**kwargs)

example_big_data/graph_widget.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class MatplotFigure(Widget):
4747
pos_y_rect_ver=NumericProperty(0)
4848
invert_rect_ver = BooleanProperty(False)
4949
invert_rect_hor = BooleanProperty(False)
50-
legend_instance = ObjectProperty(None)
50+
legend_instance = ObjectProperty(None, allownone=True)
5151
legend_do_scroll_x = BooleanProperty(True)
5252
legend_do_scroll_y = BooleanProperty(True)
5353
do_pan_x = BooleanProperty(True)
@@ -83,9 +83,16 @@ def on_figure(self, obj, value):
8383
#set default xmin/xmax and ymin/ymax
8484
self.xmin,self.xmax = self.axes.get_xlim()
8585
self.ymin,self.ymax = self.axes.get_ylim()
86-
86+
87+
if self.legend_instance:
88+
self.legend_instance.reset_legend()
89+
self.legend_instance=None
90+
8791
# Texture
8892
self._img_texture = Texture.create(size=(w, h))
93+
94+
#close last figure in memory (avoid max figure warning)
95+
matplotlib.pyplot.close()
8996

9097
def __init__(self, **kwargs):
9198
super(MatplotFigure, self).__init__(**kwargs)

example_cursor/graph_widget.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class MatplotFigure(Widget):
4747
pos_y_rect_ver=NumericProperty(0)
4848
invert_rect_ver = BooleanProperty(False)
4949
invert_rect_hor = BooleanProperty(False)
50-
legend_instance = ObjectProperty(None)
50+
legend_instance = ObjectProperty(None, allownone=True)
5151
legend_do_scroll_x = BooleanProperty(True)
5252
legend_do_scroll_y = BooleanProperty(True)
5353
do_pan_x = BooleanProperty(True)
@@ -83,9 +83,16 @@ def on_figure(self, obj, value):
8383
#set default xmin/xmax and ymin/ymax
8484
self.xmin,self.xmax = self.axes.get_xlim()
8585
self.ymin,self.ymax = self.axes.get_ylim()
86-
86+
87+
if self.legend_instance:
88+
self.legend_instance.reset_legend()
89+
self.legend_instance=None
90+
8791
# Texture
8892
self._img_texture = Texture.create(size=(w, h))
93+
94+
#close last figure in memory (avoid max figure warning)
95+
matplotlib.pyplot.close()
8996

9097
def __init__(self, **kwargs):
9198
super(MatplotFigure, self).__init__(**kwargs)

example_cursor_scatter_experimental/graph_widget_scatter.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class MatplotFigureScatter(Widget):
4747
pos_y_rect_ver=NumericProperty(0)
4848
invert_rect_ver = BooleanProperty(False)
4949
invert_rect_hor = BooleanProperty(False)
50-
legend_instance = ObjectProperty(None)
50+
legend_instance = ObjectProperty(None, allownone=True)
5151
legend_do_scroll_x = BooleanProperty(True)
5252
legend_do_scroll_y = BooleanProperty(True)
5353
do_pan_x = BooleanProperty(True)
@@ -85,10 +85,17 @@ def on_figure(self, obj, value):
8585
#set default xmin/xmax and ymin/ymax
8686
self.xmin,self.xmax = self.axes.get_xlim()
8787
self.ymin,self.ymax = self.axes.get_ylim()
88+
89+
if self.legend_instance:
90+
self.legend_instance.reset_legend()
91+
self.legend_instance=None
8892

8993
# Texture
9094
self._img_texture = Texture.create(size=(w, h))
9195

96+
#close last figure in memory (avoid max figure warning)
97+
matplotlib.pyplot.close()
98+
9299
def __init__(self, **kwargs):
93100
super(MatplotFigureScatter, self).__init__(**kwargs)
94101

example_legend/graph_widget.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class MatplotFigure(Widget):
4747
pos_y_rect_ver=NumericProperty(0)
4848
invert_rect_ver = BooleanProperty(False)
4949
invert_rect_hor = BooleanProperty(False)
50-
legend_instance = ObjectProperty(None)
50+
legend_instance = ObjectProperty(None, allownone=True)
5151
legend_do_scroll_x = BooleanProperty(True)
5252
legend_do_scroll_y = BooleanProperty(True)
5353
do_pan_x = BooleanProperty(True)
@@ -83,9 +83,16 @@ def on_figure(self, obj, value):
8383
#set default xmin/xmax and ymin/ymax
8484
self.xmin,self.xmax = self.axes.get_xlim()
8585
self.ymin,self.ymax = self.axes.get_ylim()
86-
86+
87+
if self.legend_instance:
88+
self.legend_instance.reset_legend()
89+
self.legend_instance=None
90+
8791
# Texture
8892
self._img_texture = Texture.create(size=(w, h))
93+
94+
#close last figure in memory (avoid max figure warning)
95+
matplotlib.pyplot.close()
8996

9097
def __init__(self, **kwargs):
9198
super(MatplotFigure, self).__init__(**kwargs)

0 commit comments

Comments
 (0)