diff --git a/examples/lines_bars_and_markers/timeline.py b/examples/lines_bars_and_markers/timeline.py index 68062adece8d..3911fcd6559c 100644 --- a/examples/lines_bars_and_markers/timeline.py +++ b/examples/lines_bars_and_markers/timeline.py @@ -83,12 +83,12 @@ verticalalignment="bottom" if l > 0 else "top") # format xaxis with 4 month intervals -ax.get_xaxis().set_major_locator(mdates.MonthLocator(interval=4)) -ax.get_xaxis().set_major_formatter(mdates.DateFormatter("%b %Y")) +ax.xaxis.set_major_locator(mdates.MonthLocator(interval=4)) +ax.xaxis.set_major_formatter(mdates.DateFormatter("%b %Y")) plt.setp(ax.get_xticklabels(), rotation=30, ha="right") # remove y axis and spines -ax.get_yaxis().set_visible(False) +ax.yaxis.set_visible(False) for spine in ["left", "top", "right"]: ax.spines[spine].set_visible(False) diff --git a/examples/showcase/bachelors_degrees_by_gender.py b/examples/showcase/bachelors_degrees_by_gender.py index 079fae651ead..aef1736ce761 100644 --- a/examples/showcase/bachelors_degrees_by_gender.py +++ b/examples/showcase/bachelors_degrees_by_gender.py @@ -39,8 +39,8 @@ # Ensure that the axis ticks only show up on the bottom and left of the plot. # Ticks on the right and top of the plot are generally unnecessary. -ax.get_xaxis().tick_bottom() -ax.get_yaxis().tick_left() +ax.xaxis.tick_bottom() +ax.yaxis.tick_left() fig.subplots_adjust(left=.06, right=.75, bottom=.02, top=.94) # Limit the range of the plot to only where the data is. diff --git a/examples/statistics/customized_violin.py b/examples/statistics/customized_violin.py index 3b6dac6082c3..91d56171d134 100644 --- a/examples/statistics/customized_violin.py +++ b/examples/statistics/customized_violin.py @@ -28,7 +28,7 @@ def adjacent_values(vals, q1, q3): def set_axis_style(ax, labels): - ax.get_xaxis().set_tick_params(direction='out') + ax.xaxis.set_tick_params(direction='out') ax.xaxis.set_ticks_position('bottom') ax.set_xticks(np.arange(1, len(labels) + 1)) ax.set_xticklabels(labels) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 1b0ffe60a250..302abeb00a51 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -1885,11 +1885,21 @@ def get_lines(self): return cbook.silent_list('Line2D', self.lines) def get_xaxis(self): - """Return the XAxis instance.""" + """ + Return the XAxis instance. + + The use of this function is discouraged. You should instead directly + access the attribute ``ax.xaxis``. + """ return self.xaxis def get_yaxis(self): - """Return the YAxis instance.""" + """ + Return the YAxis instance. + + The use of this function is discouraged. You should instead directly + access the attribute ``ax.yaxis``. + """ return self.yaxis get_xgridlines = _axis_method_wrapper("xaxis", "get_gridlines") diff --git a/lib/matplotlib/axes/_subplots.py b/lib/matplotlib/axes/_subplots.py index 750fbaff2577..6fb17116342d 100644 --- a/lib/matplotlib/axes/_subplots.py +++ b/lib/matplotlib/axes/_subplots.py @@ -137,12 +137,12 @@ def label_outer(self): if not lastrow: for label in self.get_xticklabels(which="both"): label.set_visible(False) - self.get_xaxis().get_offset_text().set_visible(False) + self.xaxis.get_offset_text().set_visible(False) self.set_xlabel("") if not firstcol: for label in self.get_yticklabels(which="both"): label.set_visible(False) - self.get_yaxis().get_offset_text().set_visible(False) + self.yaxis.get_offset_text().set_visible(False) self.set_ylabel("") def _make_twin_axes(self, *args, **kwargs): diff --git a/lib/matplotlib/testing/jpl_units/StrConverter.py b/lib/matplotlib/testing/jpl_units/StrConverter.py index a47bcdd343a2..576aff8935dc 100644 --- a/lib/matplotlib/testing/jpl_units/StrConverter.py +++ b/lib/matplotlib/testing/jpl_units/StrConverter.py @@ -35,7 +35,7 @@ def convert(value, unit, axis): # we delay loading to make matplotlib happy ax = axis.axes - if axis is ax.get_xaxis(): + if axis is ax.xaxis: isXAxis = True else: isXAxis = False diff --git a/lib/matplotlib/tests/test_bbox_tight.py b/lib/matplotlib/tests/test_bbox_tight.py index 95a79e300f6c..f50b272209ea 100644 --- a/lib/matplotlib/tests/test_bbox_tight.py +++ b/lib/matplotlib/tests/test_bbox_tight.py @@ -120,8 +120,8 @@ def test_noop_tight_bbox(): ax = plt.Axes(fig, [0., 0., 1., 1.]) fig.add_axes(ax) ax.set_axis_off() - ax.get_xaxis().set_visible(False) - ax.get_yaxis().set_visible(False) + ax.xaxis.set_visible(False) + ax.yaxis.set_visible(False) data = np.arange(x_size * y_size).reshape(y_size, x_size) ax.imshow(data, rasterized=True) diff --git a/lib/matplotlib/tests/test_polar.py b/lib/matplotlib/tests/test_polar.py index 768d66873e58..389d08b6eecd 100644 --- a/lib/matplotlib/tests/test_polar.py +++ b/lib/matplotlib/tests/test_polar.py @@ -135,7 +135,7 @@ def test_polar_units_2(fig_test, fig_ref): plt.figure(fig_test.number) # test {theta,r}units. plt.polar(xs_deg, ys_km, thetaunits="rad", runits="km") - assert isinstance(plt.gca().get_xaxis().get_major_formatter(), + assert isinstance(plt.gca().xaxis.get_major_formatter(), units.UnitDblFormatter) ax = fig_ref.add_subplot(projection="polar") diff --git a/lib/matplotlib/tests/test_subplots.py b/lib/matplotlib/tests/test_subplots.py index 72f72968d72b..6f6d97bb1c0c 100644 --- a/lib/matplotlib/tests/test_subplots.py +++ b/lib/matplotlib/tests/test_subplots.py @@ -27,10 +27,10 @@ def check_shared(axs, x_shared, y_shared): def check_visible(axs, x_visible, y_visible): for i, (ax, vx, vy) in enumerate(zip(axs, x_visible, y_visible)): - for l in ax.get_xticklabels() + [ax.get_xaxis().offsetText]: + for l in ax.get_xticklabels() + [ax.xaxis.offsetText]: assert l.get_visible() == vx, \ f"Visibility of x axis #{i} is incorrectly {vx}" - for l in ax.get_yticklabels() + [ax.get_yaxis().offsetText]: + for l in ax.get_yticklabels() + [ax.yaxis.offsetText]: assert l.get_visible() == vy, \ f"Visibility of y axis #{i} is incorrectly {vy}" diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index 6810de74bb91..27520f26b9b9 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -527,18 +527,18 @@ def test_unicode_minus(self, unicode_minus, result): @pytest.mark.parametrize('left, right, offset', offset_data) def test_offset_value(self, left, right, offset): fig, ax = plt.subplots() - formatter = ax.get_xaxis().get_major_formatter() + formatter = ax.xaxis.get_major_formatter() with (pytest.warns(UserWarning, match='Attempting to set identical') if left == right else nullcontext()): ax.set_xlim(left, right) - ax.get_xaxis()._update_ticks() + ax.xaxis._update_ticks() assert formatter.offset == offset with (pytest.warns(UserWarning, match='Attempting to set identical') if left == right else nullcontext()): ax.set_xlim(right, left) - ax.get_xaxis()._update_ticks() + ax.xaxis._update_ticks() assert formatter.offset == offset @pytest.mark.parametrize('use_offset', use_offset_data) diff --git a/lib/mpl_toolkits/tests/test_axes_grid1.py b/lib/mpl_toolkits/tests/test_axes_grid1.py index 96830441e8da..5121b7e970a6 100644 --- a/lib/mpl_toolkits/tests/test_axes_grid1.py +++ b/lib/mpl_toolkits/tests/test_axes_grid1.py @@ -259,8 +259,8 @@ def test_fill_facecolor(): axins = zoomed_inset_axes(ax[0], 1, loc='upper right') axins.set_xlim(0, 0.2) axins.set_ylim(0, 0.2) - plt.gca().axes.get_xaxis().set_ticks([]) - plt.gca().axes.get_yaxis().set_ticks([]) + plt.gca().axes.xaxis.set_ticks([]) + plt.gca().axes.yaxis.set_ticks([]) mark_inset(ax[0], axins, loc1=2, loc2=4, fc="b", ec="0.5") # fill with yellow by setting 'facecolor' field @@ -276,8 +276,8 @@ def test_fill_facecolor(): axins = zoomed_inset_axes(ax[1], 1, loc='upper right') axins.set_xlim(0, 0.2) axins.set_ylim(0, 0.2) - plt.gca().axes.get_xaxis().set_ticks([]) - plt.gca().axes.get_yaxis().set_ticks([]) + plt.gca().axes.xaxis.set_ticks([]) + plt.gca().axes.yaxis.set_ticks([]) mark_inset(ax[1], axins, loc1=2, loc2=4, facecolor="y", ec="0.5") # fill with green by setting 'color' field @@ -293,8 +293,8 @@ def test_fill_facecolor(): axins = zoomed_inset_axes(ax[2], 1, loc='upper right') axins.set_xlim(0, 0.2) axins.set_ylim(0, 0.2) - plt.gca().axes.get_xaxis().set_ticks([]) - plt.gca().axes.get_yaxis().set_ticks([]) + plt.gca().axes.xaxis.set_ticks([]) + plt.gca().axes.yaxis.set_ticks([]) mark_inset(ax[2], axins, loc1=2, loc2=4, color="g", ec="0.5") # fill with green but color won't show if set fill to False @@ -310,8 +310,8 @@ def test_fill_facecolor(): axins = zoomed_inset_axes(ax[3], 1, loc='upper right') axins.set_xlim(0, 0.2) axins.set_ylim(0, 0.2) - axins.get_xaxis().set_ticks([]) - axins.get_yaxis().set_ticks([]) + axins.xaxis.set_ticks([]) + axins.yaxis.set_ticks([]) mark_inset(ax[3], axins, loc1=2, loc2=4, fc="g", ec="0.5", fill=False)