From b0d8b5f6f417012b78d41d8e339d20d5cf35aa6b Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 9 Dec 2024 00:00:32 +0530 Subject: [PATCH 01/31] Update table.py --- lib/matplotlib/table.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/table.py b/lib/matplotlib/table.py index 21518c4c6726..d78f204287d4 100644 --- a/lib/matplotlib/table.py +++ b/lib/matplotlib/table.py @@ -653,7 +653,7 @@ def table(ax, cellLoc='right', colWidths=None, rowLabels=None, rowColours=None, rowLoc='left', colLabels=None, colColours=None, colLoc='center', - loc='bottom', bbox=None, edges='closed', + loc='bottom', bbox=None, edges='closed', fontsize=None, **kwargs): """ Add a table to an `~.axes.Axes`. @@ -839,4 +839,7 @@ def table(ax, table.auto_set_column_width(-1) ax.add_table(table) + # Set the fontsize if provided + if fontsize is not None: + table.set_fontsize(fontsize) return table From 46ab02ea5ae26025cbb95a2580a20f305ed572eb Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 9 Dec 2024 00:01:04 +0530 Subject: [PATCH 02/31] Update table.pyi --- lib/matplotlib/table.pyi | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/table.pyi b/lib/matplotlib/table.pyi index 07d2427f66dc..824030741e9a 100644 --- a/lib/matplotlib/table.pyi +++ b/lib/matplotlib/table.pyi @@ -8,12 +8,14 @@ from .transforms import Bbox from .typing import ColorType from collections.abc import Sequence -from typing import Any, Literal, TYPE_CHECKING +from typing import Any, Literal from pandas import DataFrame + class Cell(Rectangle): PAD: float + def __init__( self, xy: tuple[float, float], @@ -32,6 +34,7 @@ class Cell(Rectangle): def set_fontsize(self, size: float) -> None: ... def get_fontsize(self) -> float: ... def auto_set_font_size(self, renderer: RendererBase) -> float: ... + def get_text_bounds( self, renderer: RendererBase ) -> tuple[float, float, float, float]: ... @@ -45,10 +48,12 @@ class Cell(Rectangle): CustomCell = Cell + class Table(Artist): codes: dict[str, int] FONTSIZE: float AXESPAD: float + def __init__( self, ax: Axes, loc: str | None = ..., bbox: Bbox | None = ..., **kwargs ) -> None: ... @@ -68,6 +73,7 @@ class Table(Artist): def set_fontsize(self, size: float) -> None: ... def get_celld(self) -> dict[tuple[int, int], Cell]: ... + def table( ax: Axes, cellText: Sequence[Sequence[str]] | DataFrame | None = ..., @@ -83,5 +89,6 @@ def table( loc: str = ..., bbox: Bbox | None = ..., edges: str = ..., + fontsize: float | None = ..., **kwargs ) -> Table: ... From 1286c4359820733b3ff963790fb26e025ad3a072 Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 9 Dec 2024 00:01:38 +0530 Subject: [PATCH 03/31] Update test_table.py --- lib/matplotlib/tests/test_table.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/matplotlib/tests/test_table.py b/lib/matplotlib/tests/test_table.py index ee974f3cd8f9..210988474345 100644 --- a/lib/matplotlib/tests/test_table.py +++ b/lib/matplotlib/tests/test_table.py @@ -270,3 +270,25 @@ def test_table_dataframe(pd): for r, (index, row) in enumerate(df.iterrows()): for c, col in enumerate(df.columns if r == 0 else row.values): assert table[r if r == 0 else r+1, c].get_text().get_text() == str(col) + + +# Test function for fontsize in table +def test_table_fontsize(): + # Data for plotting + tableData = [['a', 1], ['b', 1]] + # Create the figure and axis objects + fig, ax = plt.subplots() + # Plot the data (although we are focusing on the table) + ax.plot(np.linspace(0, 10, 100), np.linspace(0, 10, 100) + 1) + # Add a table with fontsize=30 + t = ax.table( + cellText=tableData, + loc='top', + cellLoc='center', + fontsize=30 + ) + # Retrieve the font size from a specific cell (e.g., cell (0, 0)) + cell_fontsize = t[(0, 0)].get_fontsize() + # Assert that the fontsize is correctly set to 30 + assert cell_fontsize == 30, f"Expected fontsize 30, but got {cell_fontsize}" + From f54fd8c8f5dd0f4e354544740779e00df0b1b027 Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 9 Dec 2024 00:02:16 +0530 Subject: [PATCH 04/31] Update pyplot.py --- lib/matplotlib/pyplot.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 7e3a11b219b6..927775d422da 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -4169,6 +4169,7 @@ def table( loc="bottom", bbox=None, edges="closed", + fontsize=None, **kwargs, ): return gca().table( @@ -4185,6 +4186,7 @@ def table( loc=loc, bbox=bbox, edges=edges, + fontsize=fontsize, **kwargs, ) From f31f5c70ce26a51454e3d380cd334bd445b13668 Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 9 Dec 2024 00:26:20 +0530 Subject: [PATCH 05/31] Update table.pyi --- lib/matplotlib/table.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/matplotlib/table.pyi b/lib/matplotlib/table.pyi index 824030741e9a..4704a62c86c8 100644 --- a/lib/matplotlib/table.pyi +++ b/lib/matplotlib/table.pyi @@ -89,6 +89,5 @@ def table( loc: str = ..., bbox: Bbox | None = ..., edges: str = ..., - fontsize: float | None = ..., **kwargs ) -> Table: ... From 889f514de85f4a71a97cd6636bc60a1dd7982ad9 Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 9 Dec 2024 00:34:54 +0530 Subject: [PATCH 06/31] Update test_table.py --- lib/matplotlib/tests/test_table.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/lib/matplotlib/tests/test_table.py b/lib/matplotlib/tests/test_table.py index 210988474345..ee974f3cd8f9 100644 --- a/lib/matplotlib/tests/test_table.py +++ b/lib/matplotlib/tests/test_table.py @@ -270,25 +270,3 @@ def test_table_dataframe(pd): for r, (index, row) in enumerate(df.iterrows()): for c, col in enumerate(df.columns if r == 0 else row.values): assert table[r if r == 0 else r+1, c].get_text().get_text() == str(col) - - -# Test function for fontsize in table -def test_table_fontsize(): - # Data for plotting - tableData = [['a', 1], ['b', 1]] - # Create the figure and axis objects - fig, ax = plt.subplots() - # Plot the data (although we are focusing on the table) - ax.plot(np.linspace(0, 10, 100), np.linspace(0, 10, 100) + 1) - # Add a table with fontsize=30 - t = ax.table( - cellText=tableData, - loc='top', - cellLoc='center', - fontsize=30 - ) - # Retrieve the font size from a specific cell (e.g., cell (0, 0)) - cell_fontsize = t[(0, 0)].get_fontsize() - # Assert that the fontsize is correctly set to 30 - assert cell_fontsize == 30, f"Expected fontsize 30, but got {cell_fontsize}" - From 74541b3a3110e69eb03468dcdb9ac1db78ff76b9 Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 9 Dec 2024 00:54:27 +0530 Subject: [PATCH 07/31] Update pylab.py --- lib/matplotlib/pylab.py | 51 +++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/lib/matplotlib/pylab.py b/lib/matplotlib/pylab.py index a50779cf6d26..0bdb35625a01 100644 --- a/lib/matplotlib/pylab.py +++ b/lib/matplotlib/pylab.py @@ -1,6 +1,6 @@ """ `pylab` is a historic interface and its use is strongly discouraged. The equivalent -replacement is `matplotlib.pyplot`. See :ref:`api_interfaces` for a full overview +replacement is `matplotlib.pyplot`. See :ref:`api_interfaces` for a full overview of Matplotlib interfaces. `pylab` was designed to support a MATLAB-like way of working with all plotting related @@ -18,50 +18,47 @@ namespace. Even more severely, in the case of `pylab`, this will overwrite some builtin functions (e.g. the builtin `sum` will be replaced by `numpy.sum`), which can lead to unexpected behavior. - """ +# Utility functions and classes from Matplotlib from matplotlib.cbook import flatten, silent_list +# Main Matplotlib library import import matplotlib as mpl +# Date and time handling functions from Matplotlib from matplotlib.dates import ( date2num, num2date, datestr2num, drange, DateFormatter, DateLocator, RRuleLocator, YearLocator, MonthLocator, WeekdayLocator, DayLocator, HourLocator, MinuteLocator, SecondLocator, rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY, MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, SECONDLY, - relativedelta) - -# bring all the symbols in so folks can import them from -# pylab in one fell swoop - -## We are still importing too many things from mlab; more cleanup is needed. + relativedelta +) +# Various utility functions from mlab from matplotlib.mlab import ( - detrend, detrend_linear, detrend_mean, detrend_none, window_hanning, - window_none) + detrend, detrend_linear, detrend_mean, detrend_none, window_hanning, window_none +) +# Import specific functions from Matplotlib and Pyplot from matplotlib import cbook, mlab, pyplot as plt -from matplotlib.pyplot import * - -from numpy import * -from numpy.fft import * -from numpy.random import * -from numpy.linalg import * +# Import numpy and its submodules with alias to avoid conflicts import numpy as np import numpy.ma as ma +import numpy.fft as np_fft +import numpy.random as np_random +import numpy.linalg as np_linalg -# don't let numpy's datetime hide stdlib +# Import datetime to avoid numpy's datetime hiding the standard library's datetime import datetime -# This is needed, or bytes will be numpy.random.bytes from -# "from numpy.random import *" above -bytes = __import__("builtins").bytes -# We also don't want the numpy version of these functions -abs = __import__("builtins").abs -bool = __import__("builtins").bool -max = __import__("builtins").max -min = __import__("builtins").min -pow = __import__("builtins").pow -round = __import__("builtins").round +# Override specific numpy functions with their standard library equivalents +builtins = __import__("builtins") +bytes = builtins.bytes # Override numpy's bytes +abs = builtins.abs # Override numpy's abs +bool = builtins.bool # Override numpy's bool +max = builtins.max # Override numpy's max +min = builtins.min # Override numpy's min +pow = builtins.pow # Override numpy's pow +round = builtins.round # Override numpy's round From ff5d2786a8693745b3e92da4c8b84bfb110cd8e5 Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 9 Dec 2024 01:01:49 +0530 Subject: [PATCH 08/31] Update table.pyi --- lib/matplotlib/table.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/table.pyi b/lib/matplotlib/table.pyi index 4704a62c86c8..daacd5e1278e 100644 --- a/lib/matplotlib/table.pyi +++ b/lib/matplotlib/table.pyi @@ -89,5 +89,6 @@ def table( loc: str = ..., bbox: Bbox | None = ..., edges: str = ..., + fontsize: float | None = ..., **kwargs ) -> Table: ... From 08e153c35057ee76b4066a17c0d5c40958b7e172 Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 9 Dec 2024 01:12:48 +0530 Subject: [PATCH 09/31] Update pylab.py --- lib/matplotlib/pylab.py | 51 ++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/lib/matplotlib/pylab.py b/lib/matplotlib/pylab.py index 0bdb35625a01..a50779cf6d26 100644 --- a/lib/matplotlib/pylab.py +++ b/lib/matplotlib/pylab.py @@ -1,6 +1,6 @@ """ `pylab` is a historic interface and its use is strongly discouraged. The equivalent -replacement is `matplotlib.pyplot`. See :ref:`api_interfaces` for a full overview +replacement is `matplotlib.pyplot`. See :ref:`api_interfaces` for a full overview of Matplotlib interfaces. `pylab` was designed to support a MATLAB-like way of working with all plotting related @@ -18,47 +18,50 @@ namespace. Even more severely, in the case of `pylab`, this will overwrite some builtin functions (e.g. the builtin `sum` will be replaced by `numpy.sum`), which can lead to unexpected behavior. + """ -# Utility functions and classes from Matplotlib from matplotlib.cbook import flatten, silent_list -# Main Matplotlib library import import matplotlib as mpl -# Date and time handling functions from Matplotlib from matplotlib.dates import ( date2num, num2date, datestr2num, drange, DateFormatter, DateLocator, RRuleLocator, YearLocator, MonthLocator, WeekdayLocator, DayLocator, HourLocator, MinuteLocator, SecondLocator, rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY, MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, SECONDLY, - relativedelta -) + relativedelta) + +# bring all the symbols in so folks can import them from +# pylab in one fell swoop + +## We are still importing too many things from mlab; more cleanup is needed. -# Various utility functions from mlab from matplotlib.mlab import ( - detrend, detrend_linear, detrend_mean, detrend_none, window_hanning, window_none -) + detrend, detrend_linear, detrend_mean, detrend_none, window_hanning, + window_none) -# Import specific functions from Matplotlib and Pyplot from matplotlib import cbook, mlab, pyplot as plt +from matplotlib.pyplot import * + +from numpy import * +from numpy.fft import * +from numpy.random import * +from numpy.linalg import * -# Import numpy and its submodules with alias to avoid conflicts import numpy as np import numpy.ma as ma -import numpy.fft as np_fft -import numpy.random as np_random -import numpy.linalg as np_linalg -# Import datetime to avoid numpy's datetime hiding the standard library's datetime +# don't let numpy's datetime hide stdlib import datetime -# Override specific numpy functions with their standard library equivalents -builtins = __import__("builtins") -bytes = builtins.bytes # Override numpy's bytes -abs = builtins.abs # Override numpy's abs -bool = builtins.bool # Override numpy's bool -max = builtins.max # Override numpy's max -min = builtins.min # Override numpy's min -pow = builtins.pow # Override numpy's pow -round = builtins.round # Override numpy's round +# This is needed, or bytes will be numpy.random.bytes from +# "from numpy.random import *" above +bytes = __import__("builtins").bytes +# We also don't want the numpy version of these functions +abs = __import__("builtins").abs +bool = __import__("builtins").bool +max = __import__("builtins").max +min = __import__("builtins").min +pow = __import__("builtins").pow +round = __import__("builtins").round From 8bebcf52fdfb26dfbfc20ece0db08a4ae84cdc8a Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 9 Dec 2024 02:07:09 +0530 Subject: [PATCH 10/31] Update pyplot.py --- lib/matplotlib/pyplot.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 927775d422da..7e3a11b219b6 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -4169,7 +4169,6 @@ def table( loc="bottom", bbox=None, edges="closed", - fontsize=None, **kwargs, ): return gca().table( @@ -4186,7 +4185,6 @@ def table( loc=loc, bbox=bbox, edges=edges, - fontsize=fontsize, **kwargs, ) From 019811c89f0414f0c776ff71cec958fb36176c5c Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 9 Dec 2024 02:15:24 +0530 Subject: [PATCH 11/31] Update test_table.py --- lib/matplotlib/tests/test_table.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/matplotlib/tests/test_table.py b/lib/matplotlib/tests/test_table.py index ee974f3cd8f9..210988474345 100644 --- a/lib/matplotlib/tests/test_table.py +++ b/lib/matplotlib/tests/test_table.py @@ -270,3 +270,25 @@ def test_table_dataframe(pd): for r, (index, row) in enumerate(df.iterrows()): for c, col in enumerate(df.columns if r == 0 else row.values): assert table[r if r == 0 else r+1, c].get_text().get_text() == str(col) + + +# Test function for fontsize in table +def test_table_fontsize(): + # Data for plotting + tableData = [['a', 1], ['b', 1]] + # Create the figure and axis objects + fig, ax = plt.subplots() + # Plot the data (although we are focusing on the table) + ax.plot(np.linspace(0, 10, 100), np.linspace(0, 10, 100) + 1) + # Add a table with fontsize=30 + t = ax.table( + cellText=tableData, + loc='top', + cellLoc='center', + fontsize=30 + ) + # Retrieve the font size from a specific cell (e.g., cell (0, 0)) + cell_fontsize = t[(0, 0)].get_fontsize() + # Assert that the fontsize is correctly set to 30 + assert cell_fontsize == 30, f"Expected fontsize 30, but got {cell_fontsize}" + From 0d1689c17a01a71bb53c95acd53a4029c8d51d01 Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 9 Dec 2024 02:17:39 +0530 Subject: [PATCH 12/31] Update pyplot.py --- lib/matplotlib/pyplot.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 7e3a11b219b6..927775d422da 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -4169,6 +4169,7 @@ def table( loc="bottom", bbox=None, edges="closed", + fontsize=None, **kwargs, ): return gca().table( @@ -4185,6 +4186,7 @@ def table( loc=loc, bbox=bbox, edges=edges, + fontsize=fontsize, **kwargs, ) From d0a2d596c2d5c8d4eabbe94f26ac5dce49ab8b6f Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 9 Dec 2024 02:22:15 +0530 Subject: [PATCH 13/31] Update test_table.py --- lib/matplotlib/tests/test_table.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/matplotlib/tests/test_table.py b/lib/matplotlib/tests/test_table.py index 210988474345..5fbedddd3dce 100644 --- a/lib/matplotlib/tests/test_table.py +++ b/lib/matplotlib/tests/test_table.py @@ -291,4 +291,3 @@ def test_table_fontsize(): cell_fontsize = t[(0, 0)].get_fontsize() # Assert that the fontsize is correctly set to 30 assert cell_fontsize == 30, f"Expected fontsize 30, but got {cell_fontsize}" - From ddd10beaf331b2ffc1876ed52ef5ba4b36a440a5 Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Tue, 10 Dec 2024 14:31:40 +0530 Subject: [PATCH 14/31] Update table.pyi --- lib/matplotlib/table.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/table.pyi b/lib/matplotlib/table.pyi index daacd5e1278e..824030741e9a 100644 --- a/lib/matplotlib/table.pyi +++ b/lib/matplotlib/table.pyi @@ -89,6 +89,6 @@ def table( loc: str = ..., bbox: Bbox | None = ..., edges: str = ..., - fontsize: float | None = ..., + fontsize: float | None = ..., **kwargs ) -> Table: ... From cbb7251b7529587db4ca967978b76f43ed30d022 Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Tue, 10 Dec 2024 15:17:55 +0530 Subject: [PATCH 15/31] Update table.pyi --- lib/matplotlib/table.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/table.pyi b/lib/matplotlib/table.pyi index 824030741e9a..daacd5e1278e 100644 --- a/lib/matplotlib/table.pyi +++ b/lib/matplotlib/table.pyi @@ -89,6 +89,6 @@ def table( loc: str = ..., bbox: Bbox | None = ..., edges: str = ..., - fontsize: float | None = ..., + fontsize: float | None = ..., **kwargs ) -> Table: ... From cc6a42bcacf93cc606885e6b27f33af0cbfbaab6 Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Thu, 12 Dec 2024 12:07:54 +0530 Subject: [PATCH 16/31] Update table.py --- lib/matplotlib/table.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/table.py b/lib/matplotlib/table.py index d78f204287d4..67c720b80a7e 100644 --- a/lib/matplotlib/table.py +++ b/lib/matplotlib/table.py @@ -838,8 +838,8 @@ def table(ax, if rowLabelWidth == 0: table.auto_set_column_width(-1) - ax.add_table(table) - # Set the fontsize if provided + # set_fontsize is only effective after cells are added if fontsize is not None: table.set_fontsize(fontsize) + ax.add_table(table) return table From 7113448407b1c6fed092e5bac0d4f4b30de13b06 Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Thu, 12 Dec 2024 12:15:33 +0530 Subject: [PATCH 17/31] Update test_table.py --- lib/matplotlib/tests/test_table.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/matplotlib/tests/test_table.py b/lib/matplotlib/tests/test_table.py index 5fbedddd3dce..daa23f3534b9 100644 --- a/lib/matplotlib/tests/test_table.py +++ b/lib/matplotlib/tests/test_table.py @@ -272,22 +272,15 @@ def test_table_dataframe(pd): assert table[r if r == 0 else r+1, c].get_text().get_text() == str(col) -# Test function for fontsize in table def test_table_fontsize(): - # Data for plotting + # Test that the passed fontsize propagates to cells tableData = [['a', 1], ['b', 1]] - # Create the figure and axis objects fig, ax = plt.subplots() - # Plot the data (although we are focusing on the table) - ax.plot(np.linspace(0, 10, 100), np.linspace(0, 10, 100) + 1) - # Add a table with fontsize=30 t = ax.table( cellText=tableData, loc='top', cellLoc='center', fontsize=30 ) - # Retrieve the font size from a specific cell (e.g., cell (0, 0)) cell_fontsize = t[(0, 0)].get_fontsize() - # Assert that the fontsize is correctly set to 30 assert cell_fontsize == 30, f"Expected fontsize 30, but got {cell_fontsize}" From 4e1661d82186b52920c412f0b6fe763de99da2c9 Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Fri, 13 Dec 2024 09:34:17 +0530 Subject: [PATCH 18/31] Update table.py --- lib/matplotlib/table.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/table.py b/lib/matplotlib/table.py index 67c720b80a7e..5cbd3e0a0a3a 100644 --- a/lib/matplotlib/table.py +++ b/lib/matplotlib/table.py @@ -841,5 +841,6 @@ def table(ax, # set_fontsize is only effective after cells are added if fontsize is not None: table.set_fontsize(fontsize) + ax.add_table(table) return table From 11945543a5809214a56af6cb84445e8733f199dc Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Fri, 13 Dec 2024 09:37:44 +0530 Subject: [PATCH 19/31] Update table.pyi --- lib/matplotlib/table.pyi | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/matplotlib/table.pyi b/lib/matplotlib/table.pyi index daacd5e1278e..ad716b6089a6 100644 --- a/lib/matplotlib/table.pyi +++ b/lib/matplotlib/table.pyi @@ -12,10 +12,8 @@ from typing import Any, Literal from pandas import DataFrame - class Cell(Rectangle): PAD: float - def __init__( self, xy: tuple[float, float], @@ -34,7 +32,6 @@ class Cell(Rectangle): def set_fontsize(self, size: float) -> None: ... def get_fontsize(self) -> float: ... def auto_set_font_size(self, renderer: RendererBase) -> float: ... - def get_text_bounds( self, renderer: RendererBase ) -> tuple[float, float, float, float]: ... @@ -48,12 +45,10 @@ class Cell(Rectangle): CustomCell = Cell - class Table(Artist): codes: dict[str, int] FONTSIZE: float AXESPAD: float - def __init__( self, ax: Axes, loc: str | None = ..., bbox: Bbox | None = ..., **kwargs ) -> None: ... @@ -73,7 +68,6 @@ class Table(Artist): def set_fontsize(self, size: float) -> None: ... def get_celld(self) -> dict[tuple[int, int], Cell]: ... - def table( ax: Axes, cellText: Sequence[Sequence[str]] | DataFrame | None = ..., @@ -89,6 +83,6 @@ def table( loc: str = ..., bbox: Bbox | None = ..., edges: str = ..., - fontsize: float | None = ..., + fontsize: float | None = ..., **kwargs ) -> Table: ... From d3f1d4712bc46f5ac015d60a37d0583970687459 Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 16 Dec 2024 15:42:34 +0530 Subject: [PATCH 20/31] Update lib/matplotlib/table.py Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> --- lib/matplotlib/table.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/table.py b/lib/matplotlib/table.py index 5cbd3e0a0a3a..011bb74a5eeb 100644 --- a/lib/matplotlib/table.py +++ b/lib/matplotlib/table.py @@ -839,8 +839,8 @@ def table(ax, table.auto_set_column_width(-1) # set_fontsize is only effective after cells are added - if fontsize is not None: - table.set_fontsize(fontsize) + if "fontsize" in kwargs: + table.set_fontsize(kwargs["fontsize"]) ax.add_table(table) return table From 0857fc71c5db5297efa6347ca43c151dc0a197e4 Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 16 Dec 2024 15:42:56 +0530 Subject: [PATCH 21/31] Update lib/matplotlib/table.py Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> --- lib/matplotlib/table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/table.py b/lib/matplotlib/table.py index 011bb74a5eeb..d72f1d2ceeeb 100644 --- a/lib/matplotlib/table.py +++ b/lib/matplotlib/table.py @@ -653,7 +653,7 @@ def table(ax, cellLoc='right', colWidths=None, rowLabels=None, rowColours=None, rowLoc='left', colLabels=None, colColours=None, colLoc='center', - loc='bottom', bbox=None, edges='closed', fontsize=None, + loc='bottom', bbox=None, edges='closed', *, fontsize=None, **kwargs): """ Add a table to an `~.axes.Axes`. From c716defa9be170f842c2f4e0b2394842b818e71d Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 16 Dec 2024 15:54:02 +0530 Subject: [PATCH 22/31] Update table.pyi --- lib/matplotlib/table.pyi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/matplotlib/table.pyi b/lib/matplotlib/table.pyi index ad716b6089a6..07d2427f66dc 100644 --- a/lib/matplotlib/table.pyi +++ b/lib/matplotlib/table.pyi @@ -8,7 +8,7 @@ from .transforms import Bbox from .typing import ColorType from collections.abc import Sequence -from typing import Any, Literal +from typing import Any, Literal, TYPE_CHECKING from pandas import DataFrame @@ -83,6 +83,5 @@ def table( loc: str = ..., bbox: Bbox | None = ..., edges: str = ..., - fontsize: float | None = ..., **kwargs ) -> Table: ... From 90c69a7f326ac010a186c28b5a6ab566340840fe Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 16 Dec 2024 15:55:12 +0530 Subject: [PATCH 23/31] Update pyplot.py --- lib/matplotlib/pyplot.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 927775d422da..7e3a11b219b6 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -4169,7 +4169,6 @@ def table( loc="bottom", bbox=None, edges="closed", - fontsize=None, **kwargs, ): return gca().table( @@ -4186,7 +4185,6 @@ def table( loc=loc, bbox=bbox, edges=edges, - fontsize=fontsize, **kwargs, ) From 94da3f74cf13e54e80f9b9b440bdd9ab165580c6 Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 16 Dec 2024 16:36:17 +0530 Subject: [PATCH 24/31] Update table.pyi --- lib/matplotlib/table.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/table.pyi b/lib/matplotlib/table.pyi index 07d2427f66dc..a91ff8a1abca 100644 --- a/lib/matplotlib/table.pyi +++ b/lib/matplotlib/table.pyi @@ -6,7 +6,7 @@ from .path import Path from .text import Text from .transforms import Bbox from .typing import ColorType - +from typing import Optional, Union from collections.abc import Sequence from typing import Any, Literal, TYPE_CHECKING @@ -83,5 +83,7 @@ def table( loc: str = ..., bbox: Bbox | None = ..., edges: str = ..., + *, + fontsize: Optional[Union[int, float]] = None, **kwargs ) -> Table: ... From c2f9e8ea63e58973dafd2187558e658cc28c408f Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 16 Dec 2024 16:40:11 +0530 Subject: [PATCH 25/31] Update pyplot.py --- lib/matplotlib/pyplot.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 7e3a11b219b6..2b69300994c8 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -4169,6 +4169,8 @@ def table( loc="bottom", bbox=None, edges="closed", + *, + fontsize=None, **kwargs, ): return gca().table( @@ -4185,6 +4187,7 @@ def table( loc=loc, bbox=bbox, edges=edges, + fontsize=fontsize, **kwargs, ) From d7b14f164cc6e719aa60b42a310713d27a67c49b Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 16 Dec 2024 17:29:16 +0530 Subject: [PATCH 26/31] Update test_table.py --- lib/matplotlib/tests/test_table.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/tests/test_table.py b/lib/matplotlib/tests/test_table.py index daa23f3534b9..64281dc0f189 100644 --- a/lib/matplotlib/tests/test_table.py +++ b/lib/matplotlib/tests/test_table.py @@ -274,13 +274,11 @@ def test_table_dataframe(pd): def test_table_fontsize(): # Test that the passed fontsize propagates to cells - tableData = [['a', 1], ['b', 1]] + tableData = [['a', 1], ['b', 2]] fig, ax = plt.subplots() - t = ax.table( - cellText=tableData, - loc='top', - cellLoc='center', - fontsize=30 - ) + test_fontsize = 20 + t = ax.table(ax, cellText=tableData, loc='top', fontsize=test_fontsize) cell_fontsize = t[(0, 0)].get_fontsize() - assert cell_fontsize == 30, f"Expected fontsize 30, but got {cell_fontsize}" + assert cell_fontsize == test_fontsize, f"Expected fontsize {test_fontsize}, but got {cell_fontsize}" + cell_fontsize = t[(1, 1)].get_fontsize() + assert cell_fontsize == test_fontsize, f"Expected fontsize {test_fontsize}, but got {cell_fontsize}" From d54c3a365930d0b73e77fb5a3b68242f41066e0d Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 16 Dec 2024 17:36:09 +0530 Subject: [PATCH 27/31] Update test_table.py --- lib/matplotlib/tests/test_table.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_table.py b/lib/matplotlib/tests/test_table.py index 64281dc0f189..f0c2bee1d372 100644 --- a/lib/matplotlib/tests/test_table.py +++ b/lib/matplotlib/tests/test_table.py @@ -279,6 +279,6 @@ def test_table_fontsize(): test_fontsize = 20 t = ax.table(ax, cellText=tableData, loc='top', fontsize=test_fontsize) cell_fontsize = t[(0, 0)].get_fontsize() - assert cell_fontsize == test_fontsize, f"Expected fontsize {test_fontsize}, but got {cell_fontsize}" + assert cell_fontsize == test_fontsize, f"Actual:{test_fontsize},got:{cell_fontsize}" cell_fontsize = t[(1, 1)].get_fontsize() - assert cell_fontsize == test_fontsize, f"Expected fontsize {test_fontsize}, but got {cell_fontsize}" + assert cell_fontsize == test_fontsize, f"Actual:{test_fontsize},got:{cell_fontsize}" From 6d1fb49a58f183f801f1efa1fc96e3751db3c949 Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 16 Dec 2024 18:11:09 +0530 Subject: [PATCH 28/31] Update test_table.py --- lib/matplotlib/tests/test_table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_table.py b/lib/matplotlib/tests/test_table.py index f0c2bee1d372..783be25376be 100644 --- a/lib/matplotlib/tests/test_table.py +++ b/lib/matplotlib/tests/test_table.py @@ -277,7 +277,7 @@ def test_table_fontsize(): tableData = [['a', 1], ['b', 2]] fig, ax = plt.subplots() test_fontsize = 20 - t = ax.table(ax, cellText=tableData, loc='top', fontsize=test_fontsize) + t = ax.table(cellText=tableData, loc='top', fontsize=test_fontsize) cell_fontsize = t[(0, 0)].get_fontsize() assert cell_fontsize == test_fontsize, f"Actual:{test_fontsize},got:{cell_fontsize}" cell_fontsize = t[(1, 1)].get_fontsize() From cbdd02cd8a5a692ae77b4c39f909fb2ae4536d76 Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 16 Dec 2024 19:23:21 +0530 Subject: [PATCH 29/31] Update table.py --- lib/matplotlib/table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/table.py b/lib/matplotlib/table.py index d72f1d2ceeeb..370ce9fe922f 100644 --- a/lib/matplotlib/table.py +++ b/lib/matplotlib/table.py @@ -653,7 +653,7 @@ def table(ax, cellLoc='right', colWidths=None, rowLabels=None, rowColours=None, rowLoc='left', colLabels=None, colColours=None, colLoc='center', - loc='bottom', bbox=None, edges='closed', *, fontsize=None, + loc='bottom', bbox=None, edges='closed', **kwargs): """ Add a table to an `~.axes.Axes`. From c266b004ff866f2b84a735078e8e07923629573d Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 16 Dec 2024 19:24:12 +0530 Subject: [PATCH 30/31] Update pyplot.py --- lib/matplotlib/pyplot.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 2b69300994c8..7e3a11b219b6 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -4169,8 +4169,6 @@ def table( loc="bottom", bbox=None, edges="closed", - *, - fontsize=None, **kwargs, ): return gca().table( @@ -4187,7 +4185,6 @@ def table( loc=loc, bbox=bbox, edges=edges, - fontsize=fontsize, **kwargs, ) From 5852fe2c8cf51f498ec35a407a22c0f77d878586 Mon Sep 17 00:00:00 2001 From: saikarna913 Date: Mon, 16 Dec 2024 19:25:28 +0530 Subject: [PATCH 31/31] Update table.pyi --- lib/matplotlib/table.pyi | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/matplotlib/table.pyi b/lib/matplotlib/table.pyi index a91ff8a1abca..07d2427f66dc 100644 --- a/lib/matplotlib/table.pyi +++ b/lib/matplotlib/table.pyi @@ -6,7 +6,7 @@ from .path import Path from .text import Text from .transforms import Bbox from .typing import ColorType -from typing import Optional, Union + from collections.abc import Sequence from typing import Any, Literal, TYPE_CHECKING @@ -83,7 +83,5 @@ def table( loc: str = ..., bbox: Bbox | None = ..., edges: str = ..., - *, - fontsize: Optional[Union[int, float]] = None, **kwargs ) -> Table: ...