Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnabergoj committed Aug 18, 2022
1 parent 652e12b commit ab0f364
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
8 changes: 3 additions & 5 deletions docs/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ We simply move the plotting code into a function and pass this function to ``boo
test_x = np.linspace(-2, 3).reshape(-1, 1)
ax.scatter(data_full[:, 0], data_full[:, 1])
ax.plot(test_x, lr.predict(test_x), c='r')
ax.set_xlim(-2, 3)
ax.set_ylim(-20, 40)
bootplot(
plot_regression,
data=np.column_stack([x, y]),
output_image_path='quickstart_regression.png',
output_animation_path='quickstart_regression.gif',
xlim=(-2, 3),
ylim=(-20, 40)
output_animation_path='quickstart_regression.gif'
)
The result is an image and an animation that both display regression line uncertainty:
Expand All @@ -103,5 +103,3 @@ The result is an image and an animation that both display regression line uncert
It is often essential to manually specify axis limits.
This is to ensure all bootstrapped plots cover the same area and hence use the same axis ticks.
If axis limits are not provided, some image elements such as ticks may appear blurry depending on the plotting function.
Axis limits may be specified in the plotting function or passed to ``bootplot`` (bootplot).
The user will be warned and encouraged to provide limits if none are passed to ``bootplot``.
35 changes: 13 additions & 22 deletions examples/notebooks/categorical_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@
"outputs": [],
"source": [
"def target_distribution_bar_chart(data_subset, data_full, ax):\n",
" ax.bar(*np.unique(data_subset, return_counts=True))"
" ax.bar(*np.unique(data_subset, return_counts=True))\n",
" ax.set_xlim(-1, n_classes)\n",
" ax.set_ylim(0, 25)"
],
"metadata": {
"collapsed": false,
Expand Down Expand Up @@ -182,7 +184,10 @@
" bbox_to_anchor=(1.1, 1.1, 0, 0),\n",
" shadow=True,\n",
" title='Class'\n",
" )"
" )\n",
"\n",
" ax.set_xlim(-3, 3)\n",
" ax.set_ylim(-3, 3)"
],
"metadata": {
"collapsed": false,
Expand All @@ -196,7 +201,7 @@
"source": [
"## Running bootplot\n",
"\n",
"Having defined the plotting functions, we simply pass them to `bootplot` along with the data and axis limits. In this notebook, we will only work with the returned static images, but we could also save these to disk by specifying `output_image_path` for images and `output_animation_path` for animations. We manually specify `m = 1000` bootstrap samples to make the final result a bit smoother."
"Having defined the plotting functions, we simply pass them to `bootplot` along with the data. In this notebook, we will only work with the returned static images, but we could also save these to disk by specifying `output_image_path` for images and `output_animation_path` for animations. We manually specify `m = 1000` bootstrap samples to make the final result a bit smoother."
],
"metadata": {
"collapsed": false,
Expand All @@ -210,12 +215,7 @@
"execution_count": 6,
"outputs": [],
"source": [
"bar_chart_image = bootplot(\n",
" target_distribution_bar_chart,\n",
" data,\n",
" xlim=(-1, n_classes),\n",
" ylim=(0, 25)\n",
")"
"bar_chart_image = bootplot(target_distribution_bar_chart, data)"
],
"metadata": {
"collapsed": false,
Expand All @@ -229,13 +229,7 @@
"execution_count": 7,
"outputs": [],
"source": [
"pie_chart_image = bootplot(\n",
" target_distribution_pie_chart,\n",
" data,\n",
" m=1000,\n",
" xlim=(-3, 3),\n",
" ylim=(-3, 3)\n",
")"
"pie_chart_image = bootplot(target_distribution_pie_chart, data, m=1000)"
],
"metadata": {
"collapsed": false,
Expand Down Expand Up @@ -310,13 +304,10 @@
"def target_distribution_bar_chart_with_ground_truth(data_subset, data_full, ax):\n",
" ax.bar(*np.unique(data_subset, return_counts=True))\n",
" ax.scatter(np.arange(n_classes), binomial_pmf(np.arange(n_classes), n_classes - 1, event_probability) * len(data), color='tab:orange', edgecolor='white', s=100)\n",
" ax.set_xlim(-1, n_classes)\n",
" ax.set_ylim(0, 25)\n",
"\n",
"bar_chart_image_with_ground_truth = bootplot(\n",
" target_distribution_bar_chart_with_ground_truth,\n",
" data,\n",
" xlim=(-1, n_classes),\n",
" ylim=(0, 25)\n",
")\n",
"bar_chart_image_with_ground_truth = bootplot(target_distribution_bar_chart_with_ground_truth, data)\n",
"\n",
"plt.figure(figsize=(9, 9))\n",
"plt.imshow(bar_chart_image_with_ground_truth)\n",
Expand Down

0 comments on commit ab0f364

Please sign in to comment.