Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: replace call to deprecated Axes.get_text_heights() #375

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 22.8.0
rev: 23.10.1
hooks:
- id: black
language: python
Expand Down Expand Up @@ -41,6 +41,6 @@ repos:
language: python
language_version: python39
additional_dependencies:
- numpy~=1.22
- numpy~=1.24
- gamma-pytools~=2.1
- sklearndf~=2.2
2 changes: 2 additions & 0 deletions RELEASE_NOTES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ fully type-checked by |mypy|.
and classifiers; it is no longer necessary to wrap them into a
:class:`.RegressorPipelineDF` or :class:`.ClassifierPipelineDF` instance with empty
preprocessing
- FIX: replace a call to method ``get_text_heights()`` of :class:`matplotlib.axes.Axes`,
which is deprecated as of :mod:`matplotlib` |nbsp| 3.6


2.0.0
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ stages:
versionSpec: '3.9'
displayName: 'use Python 3.9'
- script: |
python -m pip install black~=22.8
python -m pip install black~=23.10.1
python -m black --check .
displayName: 'Run black'
- job:
Expand Down
21 changes: 11 additions & 10 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ channels:
dependencies:
# run
- gamma-pytools ~= 2.1
- joblib ~= 1.2
- joblib ~= 1.3
- lightgbm ~= 3.3
- matplotlib ~= 3.7
- numpy ~= 1.24
- matplotlib ~= 3.8
- numpy ~= 1.26
- pandas ~= 2.0
- python ~= 3.9
- scikit-learn ~= 1.2.0
- scipy ~= 1.10
- shap ~= 0.41
- python ~= 3.11
- scikit-learn ~= 1.2.2
- scipy ~= 1.11
- shap ~= 0.43
- sklearndf ~= 2.2
- typing_extensions ~= 4.3
- typing_extensions ~= 4.6
- xlrd ~= 2.0
# additional packages for notebooks etc.
- pip ~= 23.0
- pip:
Expand All @@ -30,7 +31,7 @@ dependencies:
- pydata-sphinx-theme ~= 0.8.1
# notebooks
- ipywidgets ~= 8.0
- jupyterlab ~= 3.5
- jupyterlab ~= 4.0
- openpyxl ~= 3.0
- seaborn ~= 0.12
- tableone ~= 0.7
- tableone ~= 0.8
47 changes: 33 additions & 14 deletions src/facet/simulation/viz/_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

import logging
from abc import ABCMeta, abstractmethod
from typing import Any, Sequence, TextIO, Tuple, TypeVar, Union
from typing import Any, Optional, Sequence, TextIO, Tuple, TypeVar, Union, cast

from matplotlib.axes import Axes
from matplotlib.transforms import Bbox
from mpl_toolkits.axes_grid1 import make_axes_locatable
from mpl_toolkits.axes_grid1.axes_divider import AxesDivider
from mpl_toolkits.axes_grid1.axes_size import Scaled
Expand Down Expand Up @@ -203,27 +204,44 @@ def _make_sub_axes() -> Axes:
y_min, y_max = main_ax.get_ylim()
uplift_height = abs(y_max - y_min)

def _x_axis_height() -> float:
axis_below_size_pixels: float
_, axis_below_size_pixels = main_ax.get_xaxis().get_text_heights(
def _x_axis_height(padding: float) -> float:
# get the lower bound of the x axis in data space: this is the upper
# bound of the space below the x axis
x_axis_vertical_position: float = main_ax.get_ylim()[0]

# get the upper and lower vertical bound of the tick labels
xaxis_tight_bbox: Optional[Bbox] = main_ax.get_xaxis().get_tightbbox(
self.get_renderer()
)

y0: float
y1: float
((_, y0), (_, y1)) = main_ax.transData.inverted().transform(
((0.0, 0.0), (0.0, axis_below_size_pixels))
if xaxis_tight_bbox is None:
return 0.0

x_axis_labels_lower: float
x_axis_labels_upper: float
(
x_axis_labels_lower,
x_axis_labels_upper,
) = main_ax.transData.inverted().transform(
xaxis_tight_bbox.get_points()
)[
:, 1
]

# calculate the height, and pad it with the multiple of the tick
# label height provided in arg padding
return (
max(x_axis_vertical_position - x_axis_labels_lower, 0)
+ (x_axis_labels_upper - x_axis_labels_lower) * padding
)
return abs(y1 - y0)

# calculate the height of the x axis in data space; add additional padding
axis_below_size_data = _x_axis_height() * 1.2
axis_below_size_data = _x_axis_height(padding=0.5)

# create the axes divider, then use it to append the new sub-axes at the
# bottom while leaving sufficient padding in-between to accommodate the
# main axes' x axis labels
divider: AxesDivider = make_axes_locatable(main_ax)
return divider.append_axes(
sub_axes: Axes = divider.append_axes(
position="bottom",
size=Scaled(
uplift_height * SimulationMatplotStyle.__HISTOGRAM_SIZE_RATIO
Expand All @@ -234,6 +252,7 @@ def _x_axis_height() -> float:
* (1 + SimulationMatplotStyle.__HISTOGRAM_SIZE_RATIO)
),
)
return sub_axes

ax = _make_sub_axes()

Expand All @@ -246,10 +265,10 @@ def _x_axis_height() -> float:
# reduce the horizontal margin such that half a bar is to the left of the
# leftmost tick mark (but the tick mark stays aligned with the main
# simulation chart)
x_margin, _ = ax.margins()
x_margin, _ = cast(Tuple[float, float], ax.margins())
ax.set_xmargin(
max(
0,
0.0,
(width_bars / 2 - x_margin * (n_partitions - 1))
/ (width_bars - (n_partitions - 1)),
)
Expand Down