From 9fb3aefca97ca81abbf1fe1b383f8a3698c01fd6 Mon Sep 17 00:00:00 2001 From: Michiel de Hoon Date: Mon, 15 Jun 2015 21:50:26 +0900 Subject: [PATCH 01/11] Test script. --- test.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 test.py diff --git a/test.py b/test.py new file mode 100644 index 000000000000..2e236ab2d62f --- /dev/null +++ b/test.py @@ -0,0 +1,10 @@ +import matplotlib.pyplot as plt +import matplotlib.patheffects as pe + +plt.subplot(1,1,1) +plt.annotate('line1\nline2',xy=(0.5,0.5),xycoords='axes fraction',fontsize='xx-large', + path_effects=[pe.withStroke(linewidth=1,foreground='r')]) +plt.plot([1,.4,.5,0.2],color='blue',linewidth=5) +plt.text(2.7,0.8,'More testing',fontsize=20,color='green') + +plt.show() From d57c775f69c89f41879dc9669bb1bc9671147548 Mon Sep 17 00:00:00 2001 From: Michiel de Hoon Date: Mon, 15 Jun 2015 21:56:45 +0900 Subject: [PATCH 02/11] So far so good. --- lib/matplotlib/text.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 00ac38d355ed..cc1cb5eec391 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -774,17 +774,24 @@ def draw(self, renderer): from matplotlib.patheffects import PathEffectRenderer textrenderer = PathEffectRenderer( textobj.get_path_effects(), renderer) + if textobj.get_usetex(): + textrenderer.draw_tex(gc, x, y, clean_line, + textobj._fontproperties, angle, + mtext=mtext) + else: + textrenderer.draw_text(gc, x, y, clean_line, + textobj._fontproperties, angle, + ismath=ismath, mtext=mtext) else: textrenderer = renderer - - if textobj.get_usetex(): - textrenderer.draw_tex(gc, x, y, clean_line, - textobj._fontproperties, angle, - mtext=mtext) - else: - textrenderer.draw_text(gc, x, y, clean_line, - textobj._fontproperties, angle, - ismath=ismath, mtext=mtext) + if textobj.get_usetex(): + textrenderer.draw_tex(gc, x, y, clean_line, + textobj._fontproperties, angle, + mtext=mtext) + else: + textrenderer.draw_text(gc, x, y, clean_line, + textobj._fontproperties, angle, + ismath=ismath, mtext=mtext) gc.restore() renderer.close_group('text') From fa06dae77a6bbead64f0d896dec6692241ddd9f9 Mon Sep 17 00:00:00 2001 From: Michiel de Hoon Date: Mon, 15 Jun 2015 22:01:35 +0900 Subject: [PATCH 03/11] Still OK. --- lib/matplotlib/text.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index cc1cb5eec391..3f5f40676ddb 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -749,8 +749,9 @@ def draw(self, renderer): if textobj._bbox_patch: textobj._draw_bbox(renderer, posx, posy) + color = textobj.get_color() gc = renderer.new_gc() - gc.set_foreground(textobj.get_color()) + gc.set_foreground(color) gc.set_alpha(textobj.get_alpha()) gc.set_url(textobj._url) textobj._set_gc_clip(gc) From 484fe03995cc4f2afbf9d823b8b6e5df3de8d653 Mon Sep 17 00:00:00 2001 From: Michiel de Hoon Date: Mon, 15 Jun 2015 22:03:15 +0900 Subject: [PATCH 04/11] Renamed textrenderer where possible. --- lib/matplotlib/text.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 3f5f40676ddb..569986e65a24 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -784,15 +784,14 @@ def draw(self, renderer): textobj._fontproperties, angle, ismath=ismath, mtext=mtext) else: - textrenderer = renderer if textobj.get_usetex(): - textrenderer.draw_tex(gc, x, y, clean_line, - textobj._fontproperties, angle, - mtext=mtext) + renderer.draw_tex(gc, x, y, clean_line, + textobj._fontproperties, angle, + mtext=mtext) else: - textrenderer.draw_text(gc, x, y, clean_line, - textobj._fontproperties, angle, - ismath=ismath, mtext=mtext) + renderer.draw_text(gc, x, y, clean_line, + textobj._fontproperties, angle, + ismath=ismath, mtext=mtext) gc.restore() renderer.close_group('text') From af0e5ee313e4fef6c263e7abaaa5ef490dd7f90b Mon Sep 17 00:00:00 2001 From: Michiel de Hoon Date: Mon, 15 Jun 2015 22:20:43 +0900 Subject: [PATCH 05/11] Almost there. --- lib/matplotlib/text.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 569986e65a24..a5b038bba0b5 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -750,6 +750,7 @@ def draw(self, renderer): textobj._draw_bbox(renderer, posx, posy) color = textobj.get_color() + props = textobj._fontproperties gc = renderer.new_gc() gc.set_foreground(color) gc.set_alpha(textobj.get_alpha()) @@ -776,21 +777,20 @@ def draw(self, renderer): textrenderer = PathEffectRenderer( textobj.get_path_effects(), renderer) if textobj.get_usetex(): - textrenderer.draw_tex(gc, x, y, clean_line, - textobj._fontproperties, angle, - mtext=mtext) + textrenderer._draw_text_as_path(gc, x, y, clean_line, + prop, angle, + ismath="TeX") else: - textrenderer.draw_text(gc, x, y, clean_line, - textobj._fontproperties, angle, - ismath=ismath, mtext=mtext) + textrenderer._draw_text_as_path(gc, x, y, clean_line, + props, angle, ismath) else: if textobj.get_usetex(): renderer.draw_tex(gc, x, y, clean_line, - textobj._fontproperties, angle, + props, angle, mtext=mtext) else: renderer.draw_text(gc, x, y, clean_line, - textobj._fontproperties, angle, + props, angle, ismath=ismath, mtext=mtext) gc.restore() From a9dc013d313a180780188ec712a983faf8b339c1 Mon Sep 17 00:00:00 2001 From: Michiel de Hoon Date: Mon, 15 Jun 2015 22:26:24 +0900 Subject: [PATCH 06/11] One more step to go. --- lib/matplotlib/text.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index a5b038bba0b5..5e033fd7d325 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -750,7 +750,7 @@ def draw(self, renderer): textobj._draw_bbox(renderer, posx, posy) color = textobj.get_color() - props = textobj._fontproperties + prop = textobj._fontproperties gc = renderer.new_gc() gc.set_foreground(color) gc.set_alpha(textobj.get_alpha()) @@ -777,20 +777,19 @@ def draw(self, renderer): textrenderer = PathEffectRenderer( textobj.get_path_effects(), renderer) if textobj.get_usetex(): - textrenderer._draw_text_as_path(gc, x, y, clean_line, - prop, angle, - ismath="TeX") - else: - textrenderer._draw_text_as_path(gc, x, y, clean_line, - props, angle, ismath) + ismath = "TeX" + path, transform = textrenderer._get_text_path_transform(x, y, clean_line, prop, angle, ismath) + color = gc.get_rgb() + gc.set_linewidth(0.0) + textrenderer.draw_path(gc, path, transform, rgbFace=color) else: if textobj.get_usetex(): renderer.draw_tex(gc, x, y, clean_line, - props, angle, + prop, angle, mtext=mtext) else: renderer.draw_text(gc, x, y, clean_line, - props, angle, + prop, angle, ismath=ismath, mtext=mtext) gc.restore() From ff933ece9bb2ee4b11723194f27970ce33a981d1 Mon Sep 17 00:00:00 2001 From: Michiel de Hoon Date: Mon, 15 Jun 2015 22:31:26 +0900 Subject: [PATCH 07/11] Problem fixed, continue with cleanup. --- lib/matplotlib/text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 5e033fd7d325..36020a59f790 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -753,6 +753,7 @@ def draw(self, renderer): prop = textobj._fontproperties gc = renderer.new_gc() gc.set_foreground(color) + color = gc.get_rgb() gc.set_alpha(textobj.get_alpha()) gc.set_url(textobj._url) textobj._set_gc_clip(gc) @@ -779,7 +780,6 @@ def draw(self, renderer): if textobj.get_usetex(): ismath = "TeX" path, transform = textrenderer._get_text_path_transform(x, y, clean_line, prop, angle, ismath) - color = gc.get_rgb() gc.set_linewidth(0.0) textrenderer.draw_path(gc, path, transform, rgbFace=color) else: From bf64c3cc092ee016e6770b628efbb31e8619ddef Mon Sep 17 00:00:00 2001 From: Michiel de Hoon Date: Mon, 15 Jun 2015 22:44:38 +0900 Subject: [PATCH 08/11] Use colorConverter. --- lib/matplotlib/text.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 36020a59f790..c4e92b4115d4 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -32,6 +32,7 @@ from matplotlib.backend_bases import RendererBase from matplotlib.textpath import TextPath +from matplotlib.colors import colorConverter def _process_text_args(override, fontdict=None, **kwargs): @@ -750,10 +751,9 @@ def draw(self, renderer): textobj._draw_bbox(renderer, posx, posy) color = textobj.get_color() + color = colorConverter.to_rgb(color) prop = textobj._fontproperties gc = renderer.new_gc() - gc.set_foreground(color) - color = gc.get_rgb() gc.set_alpha(textobj.get_alpha()) gc.set_url(textobj._url) textobj._set_gc_clip(gc) @@ -783,6 +783,7 @@ def draw(self, renderer): gc.set_linewidth(0.0) textrenderer.draw_path(gc, path, transform, rgbFace=color) else: + gc.set_foreground(color) if textobj.get_usetex(): renderer.draw_tex(gc, x, y, clean_line, prop, angle, From d429c71e28f63b0d1b76078c7f71013f0504402d Mon Sep 17 00:00:00 2001 From: Michiel de Hoon Date: Tue, 16 Jun 2015 21:34:31 +0900 Subject: [PATCH 09/11] Don't use the renderer. --- lib/matplotlib/text.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index c4e92b4115d4..57169d49b0a4 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -774,14 +774,14 @@ def draw(self, renderer): clean_line, ismath = textobj.is_math_text(line) if textobj.get_path_effects(): - from matplotlib.patheffects import PathEffectRenderer - textrenderer = PathEffectRenderer( - textobj.get_path_effects(), renderer) + path_effects = textobj.get_path_effects() if textobj.get_usetex(): ismath = "TeX" - path, transform = textrenderer._get_text_path_transform(x, y, clean_line, prop, angle, ismath) + path, transform = renderer._get_text_path_transform(x, y, clean_line, prop, angle, ismath) gc.set_linewidth(0.0) - textrenderer.draw_path(gc, path, transform, rgbFace=color) + for path_effect in path_effects: + path_effect.draw_path(renderer, gc, path, transform, + rgbFace=color) else: gc.set_foreground(color) if textobj.get_usetex(): From 2d71357d727f2b8b0c6be4849963b93c06a71182 Mon Sep 17 00:00:00 2001 From: Michiel de Hoon Date: Tue, 16 Jun 2015 21:37:44 +0900 Subject: [PATCH 10/11] Removing the test script. --- test.py | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 test.py diff --git a/test.py b/test.py deleted file mode 100644 index 2e236ab2d62f..000000000000 --- a/test.py +++ /dev/null @@ -1,10 +0,0 @@ -import matplotlib.pyplot as plt -import matplotlib.patheffects as pe - -plt.subplot(1,1,1) -plt.annotate('line1\nline2',xy=(0.5,0.5),xycoords='axes fraction',fontsize='xx-large', - path_effects=[pe.withStroke(linewidth=1,foreground='r')]) -plt.plot([1,.4,.5,0.2],color='blue',linewidth=5) -plt.text(2.7,0.8,'More testing',fontsize=20,color='green') - -plt.show() From 60946ec9515fc5b08ed390a8f7642df2e0f2e79e Mon Sep 17 00:00:00 2001 From: Michiel de Hoon Date: Wed, 17 Jun 2015 23:33:58 +0900 Subject: [PATCH 11/11] Follow pep8 conventions for line continuation. --- lib/matplotlib/text.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 57169d49b0a4..96d78f140be3 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -777,7 +777,8 @@ def draw(self, renderer): path_effects = textobj.get_path_effects() if textobj.get_usetex(): ismath = "TeX" - path, transform = renderer._get_text_path_transform(x, y, clean_line, prop, angle, ismath) + path, transform = renderer._get_text_path_transform( + x, y, clean_line, prop, angle, ismath) gc.set_linewidth(0.0) for path_effect in path_effects: path_effect.draw_path(renderer, gc, path, transform,