Skip to content

Commit 553eac0

Browse files
committed
add 'hist_bins' option to plot_gate() method in Session & Workspace to control histogram bins (closes #249)
1 parent 292b34c commit 553eac0

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

src/flowkit/_models/session.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,8 @@ def plot_gate(
444444
y_min=None,
445445
y_max=None,
446446
color_density=True,
447-
bin_width=4
447+
bin_width=4,
448+
hist_bins=None
448449
):
449450
"""
450451
Returns an interactive plot for the specified gate. The type of plot is
@@ -473,6 +474,10 @@ def plot_gate(
473474
:param bin_width: Bin size to use for the color density, in units of
474475
event point size. Larger values produce smoother gradients.
475476
Default is 4 for a 4x4 grid size.
477+
:param hist_bins: If the gate is only in 1 dimension, this option
478+
controls the number of bins to use for the histogram. If None,
479+
the number of bins is determined by the square root rule. This
480+
option is ignored for any gates in more than 1 dimension.
476481
:return: A Bokeh Figure object containing the interactive scatter plot.
477482
"""
478483
if gate_path is None:
@@ -509,7 +514,8 @@ def plot_gate(
509514
y_min=y_min,
510515
y_max=y_max,
511516
color_density=color_density,
512-
bin_width=bin_width
517+
bin_width=bin_width,
518+
hist_bins=hist_bins
513519
)
514520

515521
return p

src/flowkit/_models/workspace.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,8 @@ def plot_gate(
614614
y_min=None,
615615
y_max=None,
616616
color_density=True,
617-
bin_width=4
617+
bin_width=4,
618+
hist_bins=None
618619
):
619620
"""
620621
Returns an interactive plot for the specified gate. The type of plot is
@@ -643,6 +644,10 @@ def plot_gate(
643644
:param bin_width: Bin size to use for the color density, in units of
644645
event point size. Larger values produce smoother gradients.
645646
Default is 4 for a 4x4 grid size.
647+
:param hist_bins: If the gate is only in 1 dimension, this option
648+
controls the number of bins to use for the histogram. If None,
649+
the number of bins is determined by the square root rule. This
650+
option is ignored for any gates in more than 1 dimension.
646651
:return: A Bokeh Figure object containing the interactive scatter plot.
647652
"""
648653
if gate_path is None:
@@ -681,7 +686,8 @@ def plot_gate(
681686
y_min=y_min,
682687
y_max=y_max,
683688
color_density=color_density,
684-
bin_width=bin_width
689+
bin_width=bin_width,
690+
hist_bins=hist_bins
685691
)
686692

687693
return p

src/flowkit/_utils/plot_utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ def plot_gate(
632632
y_max=None,
633633
color_density=True,
634634
bin_width=4,
635+
hist_bins=None,
635636
width=600,
636637
height=600
637638
):
@@ -662,6 +663,10 @@ def plot_gate(
662663
:param bin_width: Bin size to use for the color density, in units of
663664
event point size. Larger values produce smoother gradients.
664665
Default is 4 for a 4x4 grid size.
666+
:param hist_bins: If the gate is only in 1 dimension, this option
667+
controls the number of bins to use for the histogram. If None,
668+
the number of bins is determined by the square root rule. This
669+
option is ignored for any gates in more than 1 dimension.
665670
:param height: Height of plot in pixels. Default is 600.
666671
:param width: Width of plot in pixels. Default is 600.
667672
:return: A Bokeh Figure object containing the interactive scatter plot.
@@ -802,7 +807,7 @@ def plot_gate(
802807
width=width
803808
)
804809
elif gate_type == 'hist':
805-
p = plot_histogram(x, dim_ids[0], height=height, width=width)
810+
p = plot_histogram(x, dim_ids[0], height=height, width=width, bins=hist_bins)
806811
else:
807812
raise NotImplementedError("Only histograms and scatter plots are supported in this version of FlowKit")
808813

0 commit comments

Comments
 (0)