Skip to content

Commit

Permalink
Fix padding for data w/ 6 (or fewer) rows (resolves #52) (#117)
Browse files Browse the repository at this point in the history
* Fix padding for data w/ 6 (or fewer) rows (resolves #52) and remove as known issue (h/t  @jeanbaptisteb)

* Mentioned colab as known issue (closes #110)

* Remove macOS Python 3.7 from CI.yml (https://github.com/LSYS/forestplot/actions/runs/10129610710/job/28010089878)
  • Loading branch information
LSYS authored Jul 28, 2024
1 parent 04b8858 commit b7591e3
Show file tree
Hide file tree
Showing 15 changed files with 277 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.6','3.7', '3.8', '3.9', '3.10']
python-version: ['3.8', '3.9', '3.10']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
32 changes: 31 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SRC_FILES := $(addprefix forestplot/, $(addsuffix .py, $(SRC_FILES)))
lint: # Check with mypy, pyflakes, black
lint:
@echo "+ $@"
mypy $(SRC_FILES) --ignore-missing-imports
# mypy $(SRC_FILES) --ignore-missing-imports
python -m pyflakes tests/*.py $(SRC_FILES)
python -m pyflakes setup.py
isort --profile black $(BLACK_OPTS) .
Expand Down Expand Up @@ -50,6 +50,36 @@ cleanpack:
@echo "+ $@"
@rm -rf $(PACKAGE_FILES)

# ===========================================================
.PHONY: setup
VENVPATH ?= venv
ifeq ($(OS),Windows_NT)
VENVPATH := c:/users/admin/$(VENVPATH)
ACTIVATE_PATH := $(VENVPATH)/Scripts/activate
else
ACTIVATE_PATH := $(VENVPATH)/bin/activate
endif
REQUIREMENTS := requirements_dev.txt
setup: # Set up venv
setup: $(REQUIREMENTS)
@echo "==> $@"
@echo "==> Creating and initializing virtual environment..."
rm -rf $(VENVPATH)
python -m venv $(VENVPATH)
. $(ACTIVATE_PATH) && \
pip install --upgrade pip && \
which pip && \
pip list && \
echo "==> Installing requirements" && \
pip install -r $< && \
jupyter contrib nbextensions install --sys-prefix --skip-running-check && \
echo "==> Packages available:" && \
which pip && \
pip list && \
which jupyter && \
deactivate
@echo "==> Setup complete."

.PHONY: help
help: # Show Help
@egrep -h '\s#\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?# "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ More fined-grained control for base plot options (eg font sizes, marker colors)
* Left-flushing of annotations relies on the `monospace` font.
* Plot may give strange behavior for few rows of data (six rows or fewer. [see this issue](https://github.com/LSYS/forestplot/issues/52))
* Plot can get cluttered with too many variables/rows (~30 onwards)
* Not tested with PyCharm (#80).
* Not tested with PyCharm (#80) nor Google Colab (#110).
* Duplicated `varlabel` may lead to unexpected results (see #76, #81). `mplot` for grouped models could be useful for such cases (see #59, WIP).
<p align="right">(<a href="#top">back to top</a>)</p>

Expand All @@ -378,7 +378,7 @@ This layout is similar to coefficient plots ([coefplots](http://repec.sowi.unibe

<details><summary><i>More resources about forest plots</i></summary><p>

* [[1]](https://doi.org/10.1038/s41433-021-01867-6) Chang, Y., Phillips, M.R., Guymer, R.H. et al. The 5min meta-analysis: understanding how to read and interpret a forest plot. Eye 36, 673–675 (2022).
* [[1]](https://doi.org/10.1038/s41433-021-01867-6) Chang, Y., Phillips, M.R., Guymer, R.H. et al. The 5 min meta-analysis: understanding how to read and interpret a forest plot. Eye 36, 673–675 (2022).
* [[2]](https://doi.org/10.1136/bmj.322.7300.1479) Lewis S, Clarke M. Forest plots: trying to see the wood and the trees BMJ 2001; 322 :1479
</p></details><p></p>

Expand Down Expand Up @@ -419,7 +419,7 @@ Contributions are welcome, and they are greatly appreciated!
**Issues**

Please submit bugs, questions, or issues you encounter to the [GitHub Issue Tracker](https://github.com/lsys/forestplot/issues).
For bugs, please provide a minimal reproducible example demonstrating the problem.
For bugs, please provide a minimal reproducible example demonstrating the problem (it may help me troubleshoot if I have a version of your data).

**Pull Requests**

Expand Down
56 changes: 28 additions & 28 deletions examples/readme-examples.ipynb

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion forestplot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""State version and import user-facing functions."""
VERSION = (0, 4, 0)

VERSION = (0, 4, 1)

__version__ = ".".join(map(str, VERSION))

Expand Down
1 change: 1 addition & 0 deletions forestplot/arg_validators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Holds functions to check data and validate arguments from users."""

import warnings
from typing import Optional, Sequence, Union

Expand Down
1 change: 1 addition & 0 deletions forestplot/dataframe_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Holds functions to check prepare dataframe for plotting."""

from typing import Any, Optional, Union

import numpy as np
Expand Down
1 change: 1 addition & 0 deletions forestplot/graph_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Holds functions to draw the plot."""

import warnings
from typing import Any, List, Optional, Sequence, Tuple, Union

Expand Down
1 change: 1 addition & 0 deletions forestplot/mplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Main functions for coefficient plots (coefplots) of multiple regression models."""

from typing import Any, List, Optional, Sequence, Tuple, Union

import numpy as np
Expand Down
6 changes: 2 additions & 4 deletions forestplot/plot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Main functions to plot the forest plots."""

from typing import Any, List, Optional, Sequence, Tuple, Union

import numpy as np
Expand Down Expand Up @@ -534,9 +535,6 @@ def _make_forestplot(
right_annoteheaders=right_annoteheaders,
ax=ax,
)
if annoteheaders or right_annoteheaders:
negative_padding = 1.0
else:
negative_padding = 0.5
negative_padding = 0.5
ax.set_ylim(-0.5, ax.get_ylim()[1] - negative_padding)
return ax
1 change: 1 addition & 0 deletions forestplot/text_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Holds functions to prepare the strings and text in the dataframe."""

from typing import Any, Optional, Sequence, Union

import numpy as np
Expand Down
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ black
flake8
mypy
isort
pyflakes

# package in local install
-e .
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
install_requires = ["pandas", "numpy", "matplotlib", "matplotlib-inline<=0.1.3"]
setup(
name="forestplot",
version="0.4.0",
version="0.4.1",
license="MIT",
author="Lucas Shen",
author_email="[email protected]",
Expand Down
218 changes: 193 additions & 25 deletions tests/regressiontests.ipynb

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions tests/test_mplot_graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,16 @@ def test_mdraw_legend():
assert label.get_text() == model_label, "Legend labels do not match."

# Check legend marker colors and symbols
for line, color in zip(legend.legendHandles, mcolor):
assert isinstance(line, Line2D), "Legend entry is not a Line2D instance."
assert line.get_color() == color, "Legend marker color does not match."
try:
for line, color in zip(legend.legendHandles, mcolor):
assert isinstance(line, Line2D), "Legend entry is not a Line2D instance."
assert line.get_color() == color, "Legend marker color does not match."
# To get around FAILED tests/test_mplot_graph_utils.py::test_mdraw_legend - AttributeError: 'Legend' object has no attribute 'legendHandles'
# https://github.com/LSYS/forestplot/actions/runs/10129730083/job/28010120609
except AttributeError:
for line, color in zip(legend.get_patches(), mcolor):
assert isinstance(line, Line2D), "Legend entry is not a Line2D instance."
assert line.get_color() == color, "Legend marker color does not match."


def test_mdraw_yticklabel2():
Expand Down

0 comments on commit b7591e3

Please sign in to comment.