Skip to content

Commit 9b70d09

Browse files
committed
allow ax as an argument to hist and scatter
1 parent b23fea9 commit 9b70d09

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

mpl_interactions/pyplot.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ def interactive_hist(
562562
bins="auto",
563563
weights=None,
564564
figsize=None,
565+
ax=None,
565566
slider_format_string=None,
566567
display=True,
567568
force_ipywidgets=False,
@@ -587,6 +588,8 @@ def interactive_hist(
587588
figsize : tuple or scalar
588589
If tuple it will be used as the matplotlib figsize. If a number
589590
then it will be used to scale the current rcParams figsize
591+
ax : matplotlib axis, optional
592+
if None a new figure and axis will be created
590593
slider_format_string : None, string, or dict
591594
If None a default value of decimal points will be used. For ipywidgets this uses the new f-string formatting
592595
For matplotlib widgets you need to use `%` style formatting. A string will be used as the default
@@ -633,7 +636,7 @@ def f(loc, scale):
633636
)
634637

635638
ipympl = notebook_backend()
636-
fig, ax = _gogogo_figure(ipympl, figsize=figsize)
639+
fig, ax = _gogogo_figure(ipympl, figsize=figsize, ax=ax)
637640
use_ipywidgets = ipympl or force_ipywidgets
638641

639642
pc = PatchCollection([])
@@ -689,6 +692,7 @@ def interactive_scatter(
689692
label=None,
690693
xlim="stretch",
691694
ylim="stretch",
695+
ax=None,
692696
slider_format_string=None,
693697
title=None,
694698
figsize=None,
@@ -728,6 +732,8 @@ def interactive_scatter(
728732
ylim : string or tuple of floats, optional
729733
If a tuple it will be passed to ax.set_ylim. Other options are same
730734
as xlim
735+
ax : matplotlib axis, optional
736+
if None a new figure and axis will be created
731737
slider_format_string : None, string, or dict
732738
If None a default value of decimal points will be used. For ipywidgets this uses the new f-string formatting
733739
For matplotlib widgets you need to use `%` style formatting. A string will be used as the default
@@ -794,7 +800,7 @@ def _prep_size(s):
794800

795801
params = {}
796802
ipympl = notebook_backend()
797-
fig, ax = _gogogo_figure(ipympl, figsize)
803+
fig, ax = _gogogo_figure(ipympl, figsize, ax)
798804
use_ipywidgets = ipympl or force_ipywidgets
799805
slider_format_strings = _create_slider_format_dict(slider_format_string, use_ipywidgets)
800806
scats = []

0 commit comments

Comments
 (0)