Skip to content

Commit a15369f

Browse files
authored
Merge pull request #44 from janssen/master
actually draw background in Agg version; update to use new matplotlib…
2 parents 1a309f6 + 1b114c0 commit a15369f

3 files changed

Lines changed: 38 additions & 19 deletions

File tree

backend_kivy.py

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ def close(event):
299299
from kivy.clock import Clock
300300
from distutils.version import LooseVersion
301301

302-
_mpl_1_5 = LooseVersion(matplotlib.__version__) >= LooseVersion('1.5.0')
302+
_mpl_ge_1_5 = LooseVersion(matplotlib.__version__) >= LooseVersion('1.5.0')
303+
_mpl_ge_2_0 = LooseVersion(matplotlib.__version__) >= LooseVersion('2.0.0rc1')
303304

304305
import numpy as np
305306
import io
@@ -477,7 +478,10 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
477478
for i, (path, transform) in enumerate(self._iter_collection_raw_paths(
478479
master_transform, paths, all_transforms)):
479480
transform = Affine2D(transform.get_matrix()).scale(1.0, -1.0)
480-
polygons = path.to_polygons(transform)
481+
if _mpl_ge_2_0:
482+
polygons = path.to_polygons(transform, closed_only=False)
483+
else:
484+
polygons = path.to_polygons(transform)
481485
path_codes.append(polygons)
482486
# Apply the styles and rgbFace to each one of the raw paths from
483487
# the list. Additionally a transformation is being applied to
@@ -549,7 +553,7 @@ def get_graphics(self, gc, polygons, points_line, rgbFace, closed=False):
549553
mode=str("triangle_fan")
550554
))
551555
instruction_group.add(Color(*gc.get_rgb()))
552-
if _mpl_1_5 and closed:
556+
if _mpl_ge_1_5 and not _mpl_ge_2_0 and closed:
553557
points_poly_line = points_line[:-2]
554558
else:
555559
points_poly_line = points_line
@@ -590,7 +594,10 @@ def draw_image(self, gc, x, y, im):
590594
Color(1.0, 1.0, 1.0, 1.0)
591595
Rectangle(texture=texture, pos=(x, y), size=(w, h))
592596
else:
593-
polygons = clippath.to_polygons(clippath_trans)
597+
if _mpl_ge_2_0:
598+
polygons = clippath.to_polygons(clippath_trans, closed_only=False)
599+
else:
600+
polygons = clippath.to_polygons(clippath_trans)
594601
list_canvas_instruction = self.get_path_instructions(gc, polygons,
595602
rgbFace=(1.0, 1.0, 1.0, 1.0))
596603
for widget, instructions in list_canvas_instruction:
@@ -650,11 +657,12 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
650657
self.draw_mathtext(gc, x, y, s, prop, angle)
651658
else:
652659
font = resource_find(prop.get_name() + ".ttf")
660+
color = gc.get_rgb()
653661
if font is None:
654-
plot_text = CoreLabel(font_size=prop.get_size_in_points())
662+
plot_text = CoreLabel(font_size=prop.get_size_in_points(), color=color)
655663
else:
656664
plot_text = CoreLabel(font_size=prop.get_size_in_points(),
657-
font_name=prop.get_name())
665+
font_name=prop.get_name(), color=color)
658666
plot_text.text = six.text_type("{}".format(s))
659667
if prop.get_style() == 'italic':
660668
plot_text.italic = True
@@ -680,7 +688,7 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
680688
w = ftimage.get_width()
681689
h = ftimage.get_height()
682690
texture = Texture.create(size=(w, h))
683-
if _mpl_1_5:
691+
if _mpl_ge_1_5:
684692
texture.blit_buffer(ftimage.as_rgba_str()[0][0], colorfmt='rgba',
685693
bufferfmt='ubyte')
686694
else:
@@ -698,8 +706,12 @@ def draw_path(self, gc, path, transform, rgbFace=None):
698706
rendering. Paths are received in matplotlib coordinates. The
699707
aesthetics is defined by the `GraphicsContextKivy` gc.
700708
'''
701-
polygons = path.to_polygons(transform, self.widget.width,
702-
self.widget.height)
709+
if _mpl_ge_2_0:
710+
polygons = path.to_polygons(transform, self.widget.width,
711+
self.widget.height, closed_only=False)
712+
else:
713+
polygons = path.to_polygons(transform, self.widget.width,
714+
self.widget.height)
703715
list_canvas_instruction = self.get_path_instructions(gc, polygons,
704716
closed=True, rgbFace=rgbFace)
705717
for widget, instructions in list_canvas_instruction:
@@ -726,7 +738,10 @@ def draw_markers(self, gc, marker_path, marker_trans, path,
726738
list_instructions = self._markers.get(dictkey)
727739
# creating a list of instructions for the specific marker.
728740
if list_instructions is None:
729-
polygons = marker_path.to_polygons(marker_trans)
741+
if _mpl_ge_2_0:
742+
polygons = marker_path.to_polygons(marker_trans, closed_only=False)
743+
else:
744+
polygons = marker_path.to_polygons(marker_trans)
730745
self._markers[dictkey] = self.get_path_instructions(gc,
731746
polygons, rgbFace=rgbFace)
732747
# Traversing all the positions where a marker should be rendered
@@ -748,7 +763,7 @@ def _convert_path(self, path, transform=None, clip=None, simplify=None,
748763
clip = (0.0, 0.0, self.width, self.height)
749764
else:
750765
clip = None
751-
if _mpl_1_5:
766+
if _mpl_ge_1_5:
752767
return _path.convert_to_string(
753768
path, transform, clip, simplify, sketch, 6,
754769
[b'M', b'L', b'Q', b'C', b'z'], False).decode('ascii')
@@ -992,7 +1007,7 @@ def _get_style_dict(self, rgbFace):
9921007
if self.get_joinstyle() != 'round':
9931008
attrib['line-linejoin'] = self.get_joinstyle()
9941009
if self.get_capstyle() != 'butt':
995-
attrib['line-linecap'] = _capstyle_d[self.get_capstyle()]
1010+
attrib['line-linecap'] = _capd[self.get_capstyle()]
9961011
return attrib
9971012

9981013

@@ -1174,9 +1189,9 @@ def _on_size_changed(self, *args):
11741189
'''
11751190
w, h = self.size
11761191
dpival = self.figure.dpi
1177-
winch = w / dpival
1178-
hinch = h / dpival
1179-
self.figure.set_size_inches(winch, hinch)
1192+
winch = float(w) / dpival
1193+
hinch = float(h) / dpival
1194+
self.figure.set_size_inches(winch, hinch, forward=False)
11801195
self.resize_event()
11811196
self.draw()
11821197

@@ -1238,13 +1253,14 @@ def show(self):
12381253
pass
12391254

12401255
def get_window_title(self):
1241-
return EventLoop.window.title
1256+
return Window.title
12421257

12431258
def set_window_title(self, title):
1244-
EventLoop.window.title = title
1259+
Window.title = title
12451260

12461261
def resize(self, w, h):
1247-
Window.size(w, h)
1262+
if (w > 0) and (h > 0):
1263+
Window.size = w, h
12481264

12491265
def _get_toolbar(self):
12501266
if rcParams['toolbar'] == 'toolbar2':

backend_kivyagg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ def draw(self):
196196
buf_rgba = reg.to_string()
197197
texture = Texture.create(size=(w, h))
198198
texture.flip_vertical()
199+
color = self.figure.get_facecolor()
199200
with self.canvas:
201+
Color(*color)
202+
Rectangle(pos=self.pos, size=(w, h))
200203
Color(1.0, 1.0, 1.0, 1.0)
201204
self.img_rect = Rectangle(texture=texture, pos=self.pos,
202205
size=(w, h))

examples/test_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def motionnotify(event):
3737

3838

3939
def resize(event):
40-
print('resize from mpl ', event)
40+
print('resize from mpl ', event.width, event.height)
4141

4242

4343
def scroll(event):

0 commit comments

Comments
 (0)