Skip to content

Commit b31a0e7

Browse files
authored
Update API examples (#40)
* 🎨 format notebooks - except line plot example data * 🎨 remove html_js_files entry needed for plotly6 * ⏪ format data as before, but hide input so it could be reformatted with black * 🎨 unify imports, data view and link create function in docs * 🎨 apply changes to ipynb * 🎨 format * 🔥 duplicate notebook * 🔧 move config for sphinx to conf.py - avoid having it in notebooks * 🎨 format * 🎨 hide input in histogram api example * 🎨 link API Reference of new create functions
1 parent a110f77 commit b31a0e7

File tree

11 files changed

+478
-16763
lines changed

11 files changed

+478
-16763
lines changed

docs/api_examples/bar_plot.ipynb

Lines changed: 62 additions & 4105 deletions
Large diffs are not rendered by default.

docs/api_examples/bar_plot.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262

6363
IN_COLAB = "COLAB_GPU" in os.environ
6464

65-
# %% tags=["hide-cell"]
6665
# Create a directory for outputs
6766
output_dir = "./outputs"
6867
os.makedirs(output_dir, exist_ok=True)
@@ -71,18 +70,18 @@
7170
# ### 0.2. Importing libraries
7271

7372
# %%
74-
# Imports
75-
import pandas as pd
76-
import numpy as np
7773
from pathlib import Path
7874

75+
import numpy as np
76+
import pandas as pd
77+
7978
from vuecore.plots.basic.bar import create_bar_plot
8079

8180
# %% [markdown]
8281
# ### 0.3. Create sample data
8382
# We create a synthetic dataset representing the relative abundances of common bacterial genera across various environmental samples.
8483

85-
# %%
84+
# %% tags=["hide-input"]
8685
# Set a random seed for reproducibility of the synthetic data
8786
np.random.seed(42)
8887

@@ -156,7 +155,9 @@ def make_sample(sample: str, genera: list[str]) -> list[dict]:
156155

157156
# %% [markdown]
158157
# ## 1. Basic Bar Plot
159-
# A basic bar plot can be created by simply providing the `x` and `y` columns from the DataFrame, along with style options like `title`.
158+
# A basic bar plot can be created by simply providing the `x` and `y` columns from the DataFrame,
159+
# along with style options like `title`
160+
# using [`create_bar_plot`](vuecore.plots.basic.bar.create_bar_plot).
160161

161162
# %%
162163
# Create a df with unique samples and their genera counts

docs/api_examples/box_violin_plot.ipynb

Lines changed: 58 additions & 4127 deletions
Large diffs are not rendered by default.

docs/api_examples/box_violin_plot.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,32 +64,28 @@
6464

6565
IN_COLAB = "COLAB_GPU" in os.environ
6666

67-
# %% tags=["hide-cell"]
6867
# Create a directory for outputs
6968
output_dir = "./outputs"
7069
os.makedirs(output_dir, exist_ok=True)
7170

7271
# %% [markdown]
7372
# ### 0.2. Importing libraries
74-
7573
# %%
76-
# Imports
77-
import pandas as pd
78-
import numpy as np
7974
from pathlib import Path
80-
import plotly.io as pio
75+
76+
import numpy as np
77+
import pandas as pd
8178

8279
from vuecore.plots.basic.box import create_box_plot
8380
from vuecore.plots.basic.violin import create_violin_plot
8481

85-
# Set the Plotly renderer based on the environment
86-
pio.renderers.default = "notebook"
87-
8882
# %% [markdown]
8983
# ### 0.3. Create sample data
90-
# We create a synthetic dataset simulating gene expression levels across different patient samples and treatment conditions, with each data point representing a unique gene's expression level under a specific treatment for a particular patient.
84+
# We create a synthetic dataset simulating gene expression levels across different
85+
# patient samples and treatment conditions, with each data point representing a
86+
# unique gene's expression level under a specific treatment for a particular patient.
9187

92-
# %%
88+
# %% tags=["hide-input"]
9389
# Set a random seed for reproducibility of the synthetic data
9490
np.random.seed(42)
9591

@@ -128,10 +124,13 @@
128124
"Expression": expr,
129125
}
130126
)
127+
gene_exp_df
131128

132129
# %% [markdown]
133130
# ## 1. Basic Box Plot
134-
# A basic box plot can be created by simply providing the `x` and `y` columns from the DataFrame, along with style options like `title`.
131+
# A basic box plot can be created by simply providing the `x` and `y` columns from the DataFrame,
132+
# along with style options like `title`
133+
# using [`create_box_plot`](vuecore.plots.basic.box.create_box_plot).
135134

136135
# %%
137136
# Define output file path for the PNG basic box plot
@@ -150,7 +149,9 @@
150149

151150
# %% [markdown]
152151
# ## 2. Basic Violin Plot
153-
# A basic violin plot can be created by simply providing the `x` and `y` columns from the DataFrame, along with style options like `title`.
152+
# A basic violin plot can be created by simply providing the `x` and `y` columns from the DataFrame,
153+
# along with style options like `title`
154+
# using [`create_violin_plot`](vuecore.plots.basic.violin.create_violin_plot) .
154155

155156
# %%
156157
# Define output file path for the PNG basic violin plot

docs/api_examples/histogram_plot.ipynb

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,12 @@
120120
"outputs": [],
121121
"source": [
122122
"# Imports\n",
123-
"import pandas as pd\n",
124-
"import numpy as np\n",
125123
"from pathlib import Path\n",
126-
"import plotly.io as pio\n",
127124
"\n",
128-
"from vuecore.plots.basic.histogram import create_histogram_plot\n",
125+
"import numpy as np\n",
126+
"import pandas as pd\n",
129127
"\n",
130-
"# Set the Plotly renderer based on the environment\n",
131-
"pio.renderers.default = \"notebook\""
128+
"from vuecore.plots.basic.histogram import create_histogram_plot"
132129
]
133130
},
134131
{
@@ -137,14 +134,19 @@
137134
"metadata": {},
138135
"source": [
139136
"### 0.3. Create sample data\n",
140-
"We create a synthetic dataset simulating gene expression data across two experimental conditions to demonstrate how histograms can visualize data distribution."
137+
"We create a synthetic dataset simulating gene expression data across two experimental\n",
138+
"conditions to demonstrate how histograms can visualize data distribution."
141139
]
142140
},
143141
{
144142
"cell_type": "code",
145143
"execution_count": null,
146144
"id": "ac2db647",
147-
"metadata": {},
145+
"metadata": {
146+
"tags": [
147+
"hide-input"
148+
]
149+
},
148150
"outputs": [
149151
{
150152
"data": {
@@ -222,29 +224,33 @@
222224
}
223225
],
224226
"source": [
225-
"# Set a random seed for reproducibility of the synthetic data \n",
227+
"# Set a random seed for reproducibility of the synthetic data\n",
226228
"np.random.seed(42)\n",
227229
"\n",
228230
"# Define parameters for synthetic gene expression data\n",
229231
"num_genes = 1000\n",
232+
"conditions = [\"Control\", \"Treated\"]\n",
230233
"gene_names = [f\"Gene_{i}\" for i in range(num_genes)]\n",
231234
"\n",
232235
"# Simulate expression data with a slight shift in the \"Treated\" group\n",
233-
"expression_values = np.concatenate([\n",
234-
" np.random.normal(loc=10, scale=2, size=num_genes // 2),\n",
235-
" np.random.normal(loc=12, scale=2, size=num_genes // 2)\n",
236-
"])\n",
237-
"condition_values = np.concatenate([\n",
238-
" [\"Control\"] * (num_genes // 2),\n",
239-
" [\"Treated\"] * (num_genes // 2)\n",
240-
"])\n",
236+
"expression_values = np.concatenate(\n",
237+
" [\n",
238+
" np.random.normal(loc=10, scale=2, size=num_genes // 2),\n",
239+
" np.random.normal(loc=12, scale=2, size=num_genes // 2),\n",
240+
" ]\n",
241+
")\n",
242+
"condition_values = np.concatenate(\n",
243+
" [[\"Control\"] * (num_genes // 2), [\"Treated\"] * (num_genes // 2)]\n",
244+
")\n",
241245
"\n",
242246
"# Create the DataFrame\n",
243-
"gene_exp_df = pd.DataFrame({\n",
244-
" \"Gene_ID\": gene_names,\n",
245-
" \"Expression\": expression_values,\n",
246-
" \"Condition\": condition_values\n",
247-
"})\n",
247+
"gene_exp_df = pd.DataFrame(\n",
248+
" {\n",
249+
" \"Gene_ID\": gene_names,\n",
250+
" \"Expression\": expression_values,\n",
251+
" \"Condition\": condition_values,\n",
252+
" }\n",
253+
")\n",
248254
"\n",
249255
"gene_exp_df.head()"
250256
]
@@ -255,7 +261,9 @@
255261
"metadata": {},
256262
"source": [
257263
"## 1. Basic Histogram Plot\n",
258-
"A basic histogram plot can be created by simply providing the `x` and `y` columns from the DataFrame, along with style options like `title`."
264+
"A basic histogram plot can be created by simply providing the `x` and `y` columns from the DataFrame,\n",
265+
"along with style options like `title`\n",
266+
"using [`create_histogram_plot`](vuecore.plots.basic.histogram.create_histogram_plot) ."
259267
]
260268
},
261269
{
@@ -4281,12 +4289,9 @@
42814289
" histnorm=\"probability density\",\n",
42824290
" title=\"Gene Expression Distribution by Treatment Condition\",\n",
42834291
" subtitle=\"Histogram with probability density normalized\",\n",
4284-
" labels={\n",
4285-
" \"Expression\": \"Gene Expression\",\n",
4286-
" \"Condition\": \"Treatment Condition\"\n",
4287-
" },\n",
4292+
" labels={\"Expression\": \"Gene Expression\", \"Condition\": \"Treatment Condition\"},\n",
42884293
" hover_data=[\"Gene_ID\"],\n",
4289-
" opacity=0.75, \n",
4294+
" opacity=0.75,\n",
42904295
" file_path=file_path_adv_hist_html,\n",
42914296
")\n",
42924297
"\n",

docs/api_examples/histogram_plot.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,19 @@
7373

7474
# %%
7575
# Imports
76-
import pandas as pd
77-
import numpy as np
7876
from pathlib import Path
79-
import plotly.io as pio
8077

81-
from vuecore.plots.basic.histogram import create_histogram_plot
78+
import numpy as np
79+
import pandas as pd
8280

83-
# Set the Plotly renderer based on the environment
84-
pio.renderers.default = "notebook"
81+
from vuecore.plots.basic.histogram import create_histogram_plot
8582

8683
# %% [markdown]
8784
# ### 0.3. Create sample data
88-
# We create a synthetic dataset simulating gene expression data across two experimental conditions to demonstrate how histograms can visualize data distribution.
85+
# We create a synthetic dataset simulating gene expression data across two experimental
86+
# conditions to demonstrate how histograms can visualize data distribution.
8987

90-
# %%
88+
# %% tags=["hide-input"]
9189
# Set a random seed for reproducibility of the synthetic data
9290
np.random.seed(42)
9391

@@ -120,7 +118,9 @@
120118

121119
# %% [markdown]
122120
# ## 1. Basic Histogram Plot
123-
# A basic histogram plot can be created by simply providing the `x` and `y` columns from the DataFrame, along with style options like `title`.
121+
# A basic histogram plot can be created by simply providing the `x` and `y` columns from the DataFrame,
122+
# along with style options like `title`
123+
# using [`create_histogram_plot`](vuecore.plots.basic.histogram.create_histogram_plot) .
124124

125125
# %%
126126
# Define output file path for the PNG basic histogram

0 commit comments

Comments
 (0)