From 76e80c3d094999dd8bf4fbb3deb47a55b1cea9e6 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 15 Jul 2021 23:49:11 +0200 Subject: [PATCH] Remove some usages of plt.setp() We have better ways for these. --- examples/axes_grid1/demo_axes_divider.py | 4 ++-- examples/axes_grid1/inset_locator_demo2.py | 8 ++------ examples/event_handling/ginput_manual_clabel_sgskip.py | 5 +++-- examples/images_contours_and_fields/contour_demo.py | 3 +-- examples/subplots_axes_and_figures/shared_axis_demo.py | 4 ++-- examples/ticks_and_spines/date_precision_and_epochs.py | 4 ++-- lib/matplotlib/tests/test_polar.py | 10 ++++------ 7 files changed, 16 insertions(+), 22 deletions(-) diff --git a/examples/axes_grid1/demo_axes_divider.py b/examples/axes_grid1/demo_axes_divider.py index dddc2ed4760c..51f1e4c25491 100644 --- a/examples/axes_grid1/demo_axes_divider.py +++ b/examples/axes_grid1/demo_axes_divider.py @@ -22,7 +22,7 @@ def demo_simple_image(ax): im = ax.imshow(Z, extent=extent) cb = plt.colorbar(im) - plt.setp(cb.ax.get_yticklabels(), visible=False) + cb.ax.yaxis.set_tick_params(labelright=False) def demo_locatable_axes_hard(fig): @@ -60,7 +60,7 @@ def demo_locatable_axes_hard(fig): im = ax.imshow(Z, extent=extent) plt.colorbar(im, cax=ax_cb) - plt.setp(ax_cb.get_yticklabels(), visible=False) + ax_cb.yaxis.set_tick_params(labelright=False) def demo_locatable_axes_easy(ax): diff --git a/examples/axes_grid1/inset_locator_demo2.py b/examples/axes_grid1/inset_locator_demo2.py index a999d208349a..795cb9471bdb 100644 --- a/examples/axes_grid1/inset_locator_demo2.py +++ b/examples/axes_grid1/inset_locator_demo2.py @@ -32,9 +32,7 @@ def get_demo_image(): # fix the number of ticks on the inset axes axins.yaxis.get_major_locator().set_params(nbins=7) axins.xaxis.get_major_locator().set_params(nbins=7) - -plt.setp(axins.get_xticklabels(), visible=False) -plt.setp(axins.get_yticklabels(), visible=False) +axins.tick_params(labelleft=False, labelbottom=False) def add_sizebar(ax, size): @@ -69,9 +67,7 @@ def add_sizebar(ax, size): # fix the number of ticks on the inset axes axins2.yaxis.get_major_locator().set_params(nbins=7) axins2.xaxis.get_major_locator().set_params(nbins=7) - -plt.setp(axins2.get_xticklabels(), visible=False) -plt.setp(axins2.get_yticklabels(), visible=False) +axins2.tick_params(labelleft=False, labelbottom=False) # draw a bbox of the region of the inset axes in the parent axes and # connecting lines between the bbox and the inset axes area diff --git a/examples/event_handling/ginput_manual_clabel_sgskip.py b/examples/event_handling/ginput_manual_clabel_sgskip.py index 0dc41b05230f..72140fddc142 100644 --- a/examples/event_handling/ginput_manual_clabel_sgskip.py +++ b/examples/event_handling/ginput_manual_clabel_sgskip.py @@ -27,8 +27,9 @@ def tellme(s): # Define a triangle by clicking three points -plt.clf() -plt.setp(plt.gca(), autoscale_on=False) +plt.figure() +plt.xlim(0, 1) +plt.ylim(0, 1) tellme('You will define a triangle, click to begin') diff --git a/examples/images_contours_and_fields/contour_demo.py b/examples/images_contours_and_fields/contour_demo.py index 4c98d4c8bc4c..266acccf2409 100644 --- a/examples/images_contours_and_fields/contour_demo.py +++ b/examples/images_contours_and_fields/contour_demo.py @@ -85,8 +85,7 @@ linewidths=2, extent=(-3, 3, -2, 2)) # Thicken the zero contour. -zc = CS.collections[6] -plt.setp(zc, linewidth=4) +CS.collections[6].set_linewidth(4) ax.clabel(CS, levels[1::2], # label every second level inline=True, fmt='%1.1f', fontsize=14) diff --git a/examples/subplots_axes_and_figures/shared_axis_demo.py b/examples/subplots_axes_and_figures/shared_axis_demo.py index f09e5c87759b..e475a3307288 100644 --- a/examples/subplots_axes_and_figures/shared_axis_demo.py +++ b/examples/subplots_axes_and_figures/shared_axis_demo.py @@ -42,13 +42,13 @@ ax1 = plt.subplot(311) plt.plot(t, s1) -plt.setp(ax1.get_xticklabels(), fontsize=6) +plt.tick_params('x', labelsize=6) # share x only ax2 = plt.subplot(312, sharex=ax1) plt.plot(t, s2) # make these tick labels invisible -plt.setp(ax2.get_xticklabels(), visible=False) +plt.tick_params('x', labelbottom=False) # share x and y ax3 = plt.subplot(313, sharex=ax1, sharey=ax1) diff --git a/examples/ticks_and_spines/date_precision_and_epochs.py b/examples/ticks_and_spines/date_precision_and_epochs.py index 229be0f3cde9..c50bbd234331 100644 --- a/examples/ticks_and_spines/date_precision_and_epochs.py +++ b/examples/ticks_and_spines/date_precision_and_epochs.py @@ -131,7 +131,7 @@ def _reset_epoch_for_tutorial(): fig, ax = plt.subplots(constrained_layout=True) ax.plot(xold, y) ax.set_title('Epoch: ' + mdates.get_epoch()) -plt.setp(ax.xaxis.get_majorticklabels(), rotation=40) +ax.xaxis.set_tick_params(rotation=40) plt.show() ############################################################################# @@ -140,7 +140,7 @@ def _reset_epoch_for_tutorial(): fig, ax = plt.subplots(constrained_layout=True) ax.plot(x, y) ax.set_title('Epoch: ' + mdates.get_epoch()) -plt.setp(ax.xaxis.get_majorticklabels(), rotation=40) +ax.xaxis.set_tick_params(rotation=40) plt.show() _reset_epoch_for_tutorial() # Don't do this. Just for this tutorial. diff --git a/lib/matplotlib/tests/test_polar.py b/lib/matplotlib/tests/test_polar.py index 25f29629ba0a..ea3cdfa12917 100644 --- a/lib/matplotlib/tests/test_polar.py +++ b/lib/matplotlib/tests/test_polar.py @@ -322,15 +322,13 @@ def test_polar_interpolation_steps_constant_r(fig_test, fig_ref): # Check that an extra half-turn doesn't make any difference -- modulo # antialiasing, which we disable here. p1 = (fig_test.add_subplot(121, projection="polar") - .bar([0], [1], 3*np.pi, edgecolor="none")) + .bar([0], [1], 3*np.pi, edgecolor="none", antialiased=False)) p2 = (fig_test.add_subplot(122, projection="polar") - .bar([0], [1], -3*np.pi, edgecolor="none")) + .bar([0], [1], -3*np.pi, edgecolor="none", antialiased=False)) p3 = (fig_ref.add_subplot(121, projection="polar") - .bar([0], [1], 2*np.pi, edgecolor="none")) + .bar([0], [1], 2*np.pi, edgecolor="none", antialiased=False)) p4 = (fig_ref.add_subplot(122, projection="polar") - .bar([0], [1], -2*np.pi, edgecolor="none")) - for p in [p1, p2, p3, p4]: - plt.setp(p, antialiased=False) + .bar([0], [1], -2*np.pi, edgecolor="none", antialiased=False)) @check_figures_equal(extensions=["png"])