Skip to content

Commit

Permalink
Implement coloring for histograms
Browse files Browse the repository at this point in the history
  • Loading branch information
nictru committed Mar 3, 2024
1 parent 63f9666 commit f179632
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ def plots_ui():
ui.output_plot("plot_scatter")
),
ui.card(
ui.card_header("Violin plots"),
ui.output_plot("plot_violines")
ui.card_header("Histograms"),
ui.output_ui("coloring_histograms"),
ui.output_plot("plot_histograms")
)
)

Expand Down Expand Up @@ -56,13 +57,26 @@ def plot_scatter():
cbar.set_label(pretty_names[color_col])

return fig

@output
@render.ui
def coloring_histograms():
adata = _adata.get()

if adata is None:
return

categorical_obs = [None] + [column for column in adata.obs.select_dtypes(include=["object", "category"]).columns]

return ui.input_select("histo_coloring", "Coloring", categorical_obs)

@output
@render.plot
def plot_violines():
def plot_histograms():
adata = _adata.get()
pretty_names = _pretty_names.get()
distributions = _distributions.get()
coloring = input["histo_coloring"].get()

if adata is None:
return
Expand All @@ -75,9 +89,17 @@ def plot_violines():

for i, (col, pretty_name) in enumerate(pretty_names.items()):
ax = axes[i // n_cols, i % n_cols] if n_rows > 1 else axes[i]
sns.violinplot(x=adata.obs[col], ax=ax)

kwargs = {
"x": col,
"ax": ax,
"bins": 50
}
if coloring:
kwargs["hue"] = coloring

sns.histplot(adata.obs, **kwargs)
ax.set_xlabel(pretty_name)
ax.set_ylabel('Density')

current_distribution = distributions[col]

Expand Down

0 comments on commit f179632

Please sign in to comment.