From efafd31f252c01592c2ecbe761b5a9e5c6885a74 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 18 Jul 2018 13:48:53 +0200 Subject: [PATCH] Avoid using private APIs in examples. Most fixes are trivial, except the removal of the call to _update_patch_transform() in widgets/menu.py: this is OK because calling Rectangle.draw() will itself call _update_patch_transform() via get_patch_transform(). --- examples/specialty_plots/radar_chart.py | 2 +- examples/text_labels_and_annotations/demo_text_path.py | 4 +--- examples/text_labels_and_annotations/rainbow_text.py | 6 ++++-- examples/widgets/menu.py | 1 - 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/examples/specialty_plots/radar_chart.py b/examples/specialty_plots/radar_chart.py index 9a68474cfa82..6df32b3f1a8f 100644 --- a/examples/specialty_plots/radar_chart.py +++ b/examples/specialty_plots/radar_chart.py @@ -90,7 +90,7 @@ def _gen_axes_patch(self): def _gen_axes_spines(self): if frame == 'circle': - return PolarAxes._gen_axes_spines(self) + return super()._gen_axes_spines() # The following is a hack to get the spines (i.e. the axes frame) # to draw correctly for a polygon frame. diff --git a/examples/text_labels_and_annotations/demo_text_path.py b/examples/text_labels_and_annotations/demo_text_path.py index 69330ceaabb2..d1e2d421b07c 100644 --- a/examples/text_labels_and_annotations/demo_text_path.py +++ b/examples/text_labels_and_annotations/demo_text_path.py @@ -66,9 +66,7 @@ def draw(self, renderer=None): ax = plt.subplot(211) - from matplotlib._png import read_png - fn = get_sample_data("grace_hopper.png", asfileobj=False) - arr = read_png(fn) + arr = plt.imread(get_sample_data("grace_hopper.png")) text_path = TextPath((0, 0), "!?", size=150) p = PathClippedImagePatch(text_path, arr, ec="k", diff --git a/examples/text_labels_and_annotations/rainbow_text.py b/examples/text_labels_and_annotations/rainbow_text.py index 5dce48a46431..bcfd9a38d750 100644 --- a/examples/text_labels_and_annotations/rainbow_text.py +++ b/examples/text_labels_and_annotations/rainbow_text.py @@ -48,7 +48,8 @@ def rainbow_text(x, y, strings, colors, ax=None, **kw): text = ax.text(x, y, s + " ", color=c, transform=t, **kw) text.draw(canvas.get_renderer()) ex = text.get_window_extent() - t = transforms.offset_copy(text._transform, x=ex.width, units='dots') + t = transforms.offset_copy( + text.get_transform(), x=ex.width, units='dots') # vertical version for s, c in zip(strings, colors): @@ -56,7 +57,8 @@ def rainbow_text(x, y, strings, colors, ax=None, **kw): rotation=90, va='bottom', ha='center', **kw) text.draw(canvas.get_renderer()) ex = text.get_window_extent() - t = transforms.offset_copy(text._transform, y=ex.height, units='dots') + t = transforms.offset_copy( + text.get_transform(), y=ex.height, units='dots') rainbow_text(0, 0, "all unicorns poop rainbows ! ! !".split(), diff --git a/examples/widgets/menu.py b/examples/widgets/menu.py index fa5e3a54ace0..326e28fd81a1 100644 --- a/examples/widgets/menu.py +++ b/examples/widgets/menu.py @@ -89,7 +89,6 @@ def set_extent(self, x, y, w, h): self.label.ox = x + self.padx self.label.oy = y - self.depth + self.pady/2. - self.rect._update_patch_transform() self.hover = False def draw(self, renderer):