Skip to content
Open
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
10 changes: 10 additions & 0 deletions src/spac/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ def tsne_plot(adata, color_column=None, ax=None, **kwargs):

return fig, ax

def cal_bin_num(num_rows):
bins = max(int(2 * (num_rows ** (1/3))), 1)
print(f'Automatically calculated number of bins is: {bins}')
return bins

def histogram(adata, feature=None, annotation=None, layer=None,
group_by=None, together=False, ax=None,
Expand Down Expand Up @@ -530,10 +534,16 @@ def histogram(adata, feature=None, annotation=None, layer=None,

axs = []

# Determine bins if not provided
if 'bins' not in kwargs:
num_rows = len(df)
kwargs['bins'] = cal_bin_num(num_rows)

# Prepare the data for plotting
plot_data = df.dropna(subset=[data_column])

# Plotting with or without grouping

if group_by:
groups = df[group_by].dropna().unique().tolist()
n_groups = len(groups)
Expand Down
Loading