Skip to content

BUG: pass ax parameter through to dot_plot in CombineResults.plot_forest - #9829

Merged
bashtage merged 4 commits into
statsmodels:mainfrom
EdenRochmanSharabi:fix/meta-plot-forest-ax-8718
Jul 23, 2026
Merged

bashtage merged 4 commits into
statsmodels:mainfrom
EdenRochmanSharabi:fix/meta-plot-forest-ax-8718

Conversation

@EdenRochmanSharabi

Copy link
Copy Markdown
Contributor

Pass the ax parameter through to dot_plot in CombineResults.plot_forest so that the caller's axes are reused instead of creating a new figure. Also removes the duplicate ax entry in the docstring and adds a regression test.

Closes #8718

@Aniketsy Aniketsy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR, looks good 👍

one suggestion, i think we can move this import matplotlib.pyplot as plt at top level

@EdenRochmanSharabi

Copy link
Copy Markdown
Contributor Author

Done. Thanks for the review.

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
fig_out = res1.plot_forest(ax=ax, use_t=False)
assert fig_out is fig

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check that ax has changed. Could just check that len(ax.get_children()) has changed between the init and the call.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the tests so this can move forward.

Comment thread statsmodels/stats/tests/test_meta.py Outdated

import io

import matplotlib.pyplot as plt

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We never add mpl outside if functions because it is an optional dependency.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the clarification, apologize @EdenRochmanSharabi 😿 for my previous suggestion of moving at top level

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this

Re-import matplotlib.pyplot for plotting tests and update assertions.

@bashtage bashtage left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be ready on green.

Comment thread statsmodels/stats/tests/test_meta.py Outdated

import io

import matplotlib.pyplot as plt

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
fig_out = res1.plot_forest(ax=ax, use_t=False)
assert fig_out is fig

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the tests so this can move forward.

Fix the call to get_children() by removing the argument.
@bashtage

Copy link
Copy Markdown
Member

Thanks.

@bashtage
bashtage merged commit 3e88f96 into statsmodels:main Jul 23, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CombineResult.plot_forest(ax=ax) does not pass ax to dot_plot()

3 participants