Skip to content

Commit 9bdbb32

Browse files
authored
Merge pull request #98 from samanthahamilton/Issue35-documentation
Issue35 documentation
2 parents fe449ff + 00075a3 commit 9bdbb32

File tree

4 files changed

+73
-72
lines changed

4 files changed

+73
-72
lines changed

docs/examples/heatmap-slicer.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ Compare Slices of 2D Arrays
33
===========================
44

55
.. note::
6-
Unfortunately the interactive plots won't work on a website as there is no Python kernel
7-
running. So all the interactive outputs have been replaced by gifs of what you should expect.
6+
Unfortunately the interactive plots do not work on a website because there is no Python kernel
7+
running. All of the interactive outputs have therefore been replaced by gifs of what you should expect.
88

99
The :meth:`~mpl_interactions.heatmap_slicer` function allow you to compare horizontal and/or vertical
10-
slices of an arbitrary number of 2D arrays with just your mouse.
10+
slices of an arbitrary number of 2D arrays using just your mouse.
1111

1212
.. code-block:: python
1313
@@ -28,14 +28,14 @@ Options
2828

2929
The ``interaction_type`` argument controls how the plot updates. You can either use
3030
``'move'`` in which case all mouse movements will be tracked, or you can use ``'click'``
31-
and then the plot will only update when you click on one the arrays.
31+
and the plot will only update when you click on one of the arrays.
3232

33-
The ``slices`` argument controls which slices to compare. It accepts values of ``'vertical'``, ``'horizontal'`` and ``'both'``
33+
The ``slices`` argument controls which slices to compare. It accepts values of ``'vertical'``, ``'horizontal'``, and ``'both'``.
3434

35-
Potential Improvements
35+
Potential improvements
3636
^^^^^^^^^^^^^^^^^^^^^^
3737

38-
Do you wish the heatmap_slicer was better or worked with arbitrary angles? Then you should consider helping out
38+
Do you wish the ``heatmap_slicer`` was better or worked with arbitrary angles? Then you should consider helping out
3939
on one of the open issues for improving it!
4040

4141
1. `Improve the slices argument <https://github.com/ianhi/mpl-interactions/issues/57>`_

docs/examples/image-segmentation.rst

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
Image Segmentation
33
==================
44

5-
Hopefully you won't often be faced with the task of manually segmenting images. However, for the times when you must
5+
Hopefully you won't often be faced with the task of manually segmenting images. However, for the times when you must,
66
it's nice to not need to leave the comfort of python for some other program. Thus we arrive at the :class:`~mpl_interactions.image_segmenter` class.
77

8-
(Credit where it's due: This tool was developed as part of a final project in Pavlos Protopapas' class `AC295 <https://harvard-iacs.github.io/2020-AC295/>`_, you can read more about it
9-
in the project's final write up on `towards data science <https://towardsdatascience.com/how-we-built-an-easy-to-use-image-segmentation-tool-with-transfer-learning-546efb6ae98>`_)
8+
(Credit where it's due: This tool was developed as part of a final project in Pavlos Protopapas' class `AC295 <https://harvard-iacs.github.io/2020-AC295/>`_ and you can read more about it
9+
in the project's final write up on `towards data science <https://towardsdatascience.com/how-we-built-an-easy-to-use-image-segmentation-tool-with-transfer-learning-546efb6ae98>`_.)
1010

1111

1212
.. code-block:: python
@@ -23,22 +23,25 @@ in the project's final write up on `towards data science <https://towardsdatasci
2323
# If you don't keep a reference to the object the call backs will fail
2424
segmenter = image_segmenter(image, nclasses = 3, mask_colors='red', mask_alpha=.76, figsize=(7,7))
2525
26-
# if working in a jupyter notebook
26+
# If working in a Jupyter Notebook
2727
display(segmenter)
2828
29-
This will create a matplotlib figure with the image in it. It will automatically apply
30-
:meth:`~mpl_interactions.zoom_factory` and :meth:`~mpl_interactions.panhandler` so you can scroll to
31-
zoom and use middle click to pan. If you left click and drag you can start creating the mask over the image.
29+
This will create an image in a Matplotlib figure. It will automatically apply
30+
:meth:`~mpl_interactions.zoom_factory` and :meth:`~mpl_interactions.panhandler`, so now you can:
31+
32+
* Scroll to zoom
33+
* Use middle click to pan
34+
* Left click and drag to start creating the mask over the image
3235

3336
.. image:: ../_static/segment.gif
3437

35-
You can switch which class you are marking by directly modifying the `segmenter`'s `current_class` variable.
38+
You can switch which class you are marking by directly modifying the ``segmenter``'s ``current_class`` variable:
3639

3740
.. code-block:: python
3841
3942
segmenter.current_class = 2
4043
41-
and you can always directly the 2D mask with:
44+
And you can always direct the 2D mask with:
4245

4346
.. code-block:: python
4447
@@ -49,9 +52,9 @@ and you can always directly the 2D mask with:
4952
Loading existing masks
5053
----------------------
5154

52-
You can also load an existing mask. You will need to ensure that it does not contain values greater
53-
than nclasses and that it has the same shape as the image. There are currently no safegaurds for
54-
this and when there are exceptions in a matplotlib callback they can be hard to see in the notebook - so be careful!
55+
You can also load an existing mask. You only need to ensure that (1) it does not contain values greater
56+
than nclasses, and (2) that it has the same shape as the image. There are currently no safegaurds for
57+
this, and when there are exceptions in a Matplotlib callback they can be hard to see in the notebook - so be careful!
5558

5659
.. code-block:: python
5760

docs/examples/mpl-sliders.rst

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,23 @@ Using Matplotlib Widgets
66
When using Matplotlib widgets you need to make sure you always keep a reference to the control sliders, otherwise the callbacks
77
will be garbage collected and cease to work.
88

9-
This page is dedicated to showing how to use the ``interactive_*`` functions such as ``interactive_plot`` with Matplotlib widgets. For
10-
a more general discussion of how to use the ``pyplot`` submodule see the :doc:`pyplot-notebook` page.
9+
This page is dedicated to showing how to use the ``interactive_*`` functions---such as ``interactive_plot``---with Matplotlib widgets. For
10+
a more general discussion of how to use the ``pyplot`` submodule see the :doc:`pyplot-notebooks` page.
11+
1112

1213
Differences from ipywidgets sliders
1314
-----------------------------------
14-
**1.**
15-
16-
mpl-sliders are different form ipywidgets sliders in that they will only take a min and and max with
17-
an optional step. Whereas for ipywidgets sliders you need to specify all the values (at least until version 8).
15+
**1.** mpl-sliders are different from ipywidgets sliders in that they will only take a min and and max with
16+
an optional step, while for ipywidgets sliders you need to specify all values (at least until version 8).
1817
A consequence of this is that the various ``interactive_*`` methods will only use the first two values of any tuples
1918
passed as a parameter (i.e. they will ignore the ``num`` argument to linspace).
2019

21-
**2.**
22-
23-
Laying out Matplotlib widgets is signifcantly more difficult than laying out elements in a webbrowser. So if you
24-
pass an existing matplotlib widget a parameter it will update the plot as expected. However the ``interactive_*``
25-
methods will not display it for you. In contrast when using ipywidgets widgets if you give a widget as a parameter
20+
**2.** Laying out Matplotlib widgets is signifcantly more difficult than laying out elements in a web browser. If you
21+
pass an existing Matplotlib widget a parameter then the plot will update as expected; however, the ``interactive_*``
22+
methods will *not* display it for you. Alternatively, when using ipywidgets widgets, if you give a widget as a parameter
2623
it will be included in the display of the controls created by the function.
2724

28-
Basic Example
25+
Basic example
2926
-------------
3027

3128
If you are not using the ``ipympl`` backend then ``mpl_interactions`` will automatically create a new figure to hold all the controls.
@@ -47,12 +44,14 @@ If you are not using the ``ipympl`` backend then ``mpl_interactions`` will autom
4744
4845
.. image:: interactive-plot-images/mpl-sliders.gif
4946

50-
Custom Positioning of Matplotlib Widgets
47+
Custom positioning of Matplotlib widgets
5148
----------------------------------------
5249

53-
There does not seem to be a consistent and simple way to layout Matplotlib widgets in the same figure as the plot that is to be controlled.
54-
So current mpl_interactions will open a new figure to place all the controls in. If you would like the sliders and the plot to live in the same
55-
figure then you will need to create your own Slider widget and use the :meth:`~mpl_interactions.interactive_plot_factory` function:
50+
There does not seem to be a consistent and simple way to layout Matplotlib widgets in the same figure as the controlled plot.
51+
To address this, mpl_interactions will open a new figure to place all the controls.
52+
53+
If you would like the sliders and the plot to live in the same figure, you will need to create your own Slider widget and use
54+
the :meth:`~mpl_interactions.interactive_plot_factory` function:
5655

5756
.. code-block:: python
5857

docs/examples/pyplot-notebook.rst

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ Line plots
44

55
.. note::
66
Unfortunately the interactive plots won't work on a website as there is no Python kernel
7-
running. So for all the interactive outputs have been replaced by gifs of what you should expect.
7+
running. So for this site all the interactive outputs have been replaced by gifs of what you will see.
88

9-
On this example page all of the outputs will use ipywidgets widgets for controls. However, if you are
10-
not working in a Jupyter notebook then the examples here will still work with the built-in Matplolitb widgets.
11-
For examples that that explicitly use matplotlib widgets instead of ipywidgets check out the :doc:`mpl-sliders` page.
9+
On this example page all of the outputs will use **ipywidgets** widgets for controls. If you are
10+
not working in a Jupyter Notebook the examples here will still work with the built-in Matplolitb widgets.
11+
For examples that that explicitly use Matplotlib widgets instead of ipywidgets see the :doc:`mpl-sliders` page.
1212

1313

1414
.. jupyter-execute::
1515

16-
# only run these lines if you are using a jupyter notebook or jupyter lab
16+
# only run these lines if you are using a Jupyter Notebook or JupyterLab
1717
%matplotlib ipympl
1818
import ipywidgets as widgets
1919

@@ -23,11 +23,11 @@ For examples that that explicitly use matplotlib widgets instead of ipywidgets c
2323
from mpl_interactions import interactive_plot, interactive_plot_factory
2424

2525

26-
Simple Example
26+
Simple example
2727
--------------
2828

29-
To use the interactive plot function all you need to do is write a function that will
30-
return a numpy array or a list of numbers. You can provide the parameters that you want
29+
To use the interactive plot function, write a function that will
30+
return a NumPy array or a list of numbers. You can provide the parameters you want
3131
to vary with sliders as keyword arguments to the :meth:`~mpl_interactions.interactive_plot` function.
3232

3333

@@ -39,7 +39,7 @@ to vary with sliders as keyword arguments to the :meth:`~mpl_interactions.intera
3939
def f(x, tau, beta):
4040
return np.sin(x*tau)*x**beta
4141

42-
and then to display the plot
42+
Then to display the plot:
4343

4444
.. code-block:: python
4545
@@ -51,24 +51,25 @@ and then to display the plot
5151
Other ways to set parameter values
5252
----------------------------------
5353

54-
You can set parameters with any of the following:
54+
You can set parameters using any of the following:
5555

56-
- **numpy array/list** - Creates a slider with the values in the array
57-
- **tuple** - Acts as an argument to linspace. Can have either 2 or 3 items
56+
- **NumPy array/list** - Creates a slider with the values in the array
57+
- **tuple** - Acts as an argument to linspace (can have either 2 or 3 items)
5858
- **set** - Creates a categorical selector (order will not preserved)
5959
- **set(tuple())** - Categorical selector with order maintained
6060
- **scalar** - Fixed value
61-
- **ipywidgets.Widget** any subclass of ``ipywidgets.Widget`` that has a ``value`` attribute can be used
62-
- **matplotlib.widgets.Slider** or **RadioButton** - Note this cannot be used at the same time as an ipywidgets.Widget
61+
- **ipywidgets.Widget** - any subclass of ``ipywidgets.Widget`` that has a ``value`` attribute can be used
62+
- **matplotlib.widgets.Slider** or **RadioButton** - Note this cannot be used at the same time as an ``ipywidgets.Widget``
6363

64-
Here is an example using all of the possibilities with a dummy function. The ``display=False``
65-
prevent the widgets from being automatically displayed which makes it easier to render them in this webpage,
66-
but in general you should not need to use that.
64+
Here is an example using all of the possibilities with a dummy function.
6765

6866

6967
.. note::
7068
The slider labels will not update here as that update requires a Python kernel.
7169

70+
Also, ``display=False`` prevents the widgets from being automatically displayed, making it easier to render
71+
them on this webpage. In general you should not need to use it.
72+
7273
.. jupyter-execute::
7374

7475
def foo(x, **kwargs):
@@ -82,12 +83,12 @@ but in general you should not need to use that.
8283
f = widgets.Checkbox(value=True, description='A checkbox!!')
8384
display(interactive_plot(foo, x=x, a=a, b=b, c=c, d=d, e=e, f_=f, display=False)[-1])
8485

85-
Multiple Functions
86+
Multiple functions
8687
------------------
8788

8889
To plot multiple functions simply pass a list of functions as the first argument ``interactive_plot([f1, f2],...)``.
89-
Also, whenever you add a legend to the resulting plot the names of the functions will be used as the labels, unless you
90-
override that using the :ref:`plot_kwargs <plot-kwargs-section>` argument.
90+
When you add a legend to the resulting plot, the function names will be used as the labels unless overriden
91+
using the :ref:`plot_kwargs <plot-kwargs-section>` argument.
9192

9293
.. code-block:: python
9394
@@ -102,18 +103,18 @@ override that using the :ref:`plot_kwargs <plot-kwargs-section>` argument.
102103

103104
Styling
104105
-------
105-
Calling ``interactive_plot`` will create and display a new figure for you. After that you can
106-
use standard ``pyplot`` command to continue to modify the plot or you can use the references to the ``figure`` and ``axis``
107-
that are returned by interactive_plot. Though be careful, anything you add will not be affected by the sliders.
106+
Calling ``interactive_plot`` will create and display a new figure. Then you can either
107+
use the standard ``pyplot`` command to continue modifying the plot, or you can use the references to the ``figure`` and ``axis``
108+
that are returned by ``interactive_plot``. Though be careful, anything you add will not be affected by the sliders.
108109

109110

110111

111-
Slider Precision
112+
Slider precision
112113
^^^^^^^^^^^^^^^^
113114

114-
You can change the precision of individual slider displays by passing slider_format_string as a dictionary.
115-
The below example will give the tau slider 99 decimal points of precision and use scientific notation to display it. The
116-
beta slider will use the default 1 decimal point of precision
115+
You can change the precision of individual slider displays by passing ``slider_format_string`` as a dictionary.
116+
The example below gives the tau slider 99 decimal points of precision and uses scientific notation to display it. The
117+
beta slider uses the default 1 decimal point of precision.
117118

118119
.. code-block:: python
119120
@@ -126,26 +127,24 @@ Axis limits
126127
You can control how the ``xlim/ylim`` behaves using the ``xlim/ylim`` arguments.
127128
The options are:
128129

129-
1. ``'stretch'`` - The default, allow the x/y axes to expand but never shrink
130-
2. ``'auto'`` - autoscale the limits for every plot update
131-
3. ``'fixed'`` - never automatically update the limits
130+
1. ``'stretch'`` - The default; allows the x/y axes to expand but never shrink
131+
2. ``'auto'`` - Autoscales the limits for every plot update
132+
3. ``'fixed'`` - Never automatically update the limits
132133
4. [``float``, ``float``] - This value will be passed through to ``plt.xlim`` or ``plt.ylim``
133134

134135
Reference parameter values in the Title
135136
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
136-
You can make the title auto update with information about the values by using ``title`` argument.
137-
Just use the name of one of the parameters as in a format specifier in the string.
138-
e.g. to put the value of `tau` in the title and round it to two decimals use the following
139-
title string: ``{'tau:.2f}'``
137+
You can make the Title automatically update with information about the values by using ``title`` argument.
138+
Use the name of one of the parameters as a format specifier in the string. For example use the following title string
139+
to put the value of `tau` in the title and round it to two decimalsg: ``{'tau:.2f}'``
140140

141141
.. _plot-kwargs-section:
142142

143143
Matplolitb keyword arguments
144144
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
145145

146-
You can pass keyword arguments (kwargs) through to the ``plt.plot`` calls using the ``plot_kwargs``
147-
argument to ``interactive_plot``. For example to add a label and some styling to one of the functions you
148-
can do the following:
146+
You can pass keyword arguments (*kwargs*) through to the ``plt.plot`` calls using the ``plot_kwargs``
147+
argument to ``interactive_plot``. For example, to add a label and some styling to one of the functions try the following:
149148

150149
.. code-block:: python
151150

0 commit comments

Comments
 (0)