From 63122d40c437748138d3fa9fddd39f537882d07b Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Thu, 31 Oct 2024 17:49:47 -0500 Subject: [PATCH] Cleanup converter docs and StrCategoryConverter behavior - Use getter in docs - Use a single instance of StrCategoryConverter for all types - avoids warning since some methods convert to `np.str_` and others are just `str`, which previously got separate instances - added test --- galleries/users_explain/axes/axes_units.py | 6 +++--- lib/matplotlib/category.py | 9 +++++---- lib/matplotlib/tests/test_category.py | 8 ++++++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/galleries/users_explain/axes/axes_units.py b/galleries/users_explain/axes/axes_units.py index 6b486f007a12..a9159abe33ce 100644 --- a/galleries/users_explain/axes/axes_units.py +++ b/galleries/users_explain/axes/axes_units.py @@ -236,7 +236,7 @@ x = np.arange(100) ax = axs[0] ax.plot(x, x) -label = f'Converter: {ax.xaxis.converter}\n ' +label = f'Converter: {ax.xaxis.get_converter()}\n ' label += f'Locator: {ax.xaxis.get_major_locator()}\n' label += f'Formatter: {ax.xaxis.get_major_formatter()}\n' ax.set_xlabel(label) @@ -245,7 +245,7 @@ time = np.arange('1980-01-01', '1980-06-25', dtype='datetime64[D]') x = np.arange(len(time)) ax.plot(time, x) -label = f'Converter: {ax.xaxis.converter}\n ' +label = f'Converter: {ax.xaxis.get_converter()}\n ' label += f'Locator: {ax.xaxis.get_major_locator()}\n' label += f'Formatter: {ax.xaxis.get_major_formatter()}\n' ax.set_xlabel(label) @@ -255,7 +255,7 @@ names = list(data.keys()) values = list(data.values()) ax.plot(names, values) -label = f'Converter: {ax.xaxis.converter}\n ' +label = f'Converter: {ax.xaxis.get_converter()}\n ' label += f'Locator: {ax.xaxis.get_major_locator()}\n' label += f'Formatter: {ax.xaxis.get_major_formatter()}\n' ax.set_xlabel(label) diff --git a/lib/matplotlib/category.py b/lib/matplotlib/category.py index 4ac2379ea5f5..14cffd914a2a 100644 --- a/lib/matplotlib/category.py +++ b/lib/matplotlib/category.py @@ -227,7 +227,8 @@ def update(self, data): # Register the converter with Matplotlib's unit framework -units.registry[str] = StrCategoryConverter() -units.registry[np.str_] = StrCategoryConverter() -units.registry[bytes] = StrCategoryConverter() -units.registry[np.bytes_] = StrCategoryConverter() +# Intentionally set to a single instance +units.registry[str] = \ + units.registry[np.str_] = \ + units.registry[bytes] = \ + units.registry[np.bytes_] = StrCategoryConverter() diff --git a/lib/matplotlib/tests/test_category.py b/lib/matplotlib/tests/test_category.py index fd4aec88b574..b724e5839c4d 100644 --- a/lib/matplotlib/tests/test_category.py +++ b/lib/matplotlib/tests/test_category.py @@ -246,6 +246,14 @@ def test_update_plot(self, plotter): axis_test(ax.xaxis, ['a', 'b', 'd', 'c']) axis_test(ax.yaxis, ['e', 'g', 'f', 'a', 'b', 'd']) + def test_update_plot_heterogenous_plotter(self): + ax = plt.figure().subplots() + ax.scatter(['a', 'b'], ['e', 'g']) + ax.plot(['a', 'b', 'd'], ['f', 'a', 'b']) + ax.bar(['b', 'c', 'd'], ['g', 'e', 'd']) + axis_test(ax.xaxis, ['a', 'b', 'd', 'c']) + axis_test(ax.yaxis, ['e', 'g', 'f', 'a', 'b', 'd']) + failing_test_cases = [("mixed", ['A', 3.14]), ("number integer", ['1', 1]), ("string integer", ['42', 42]), pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy