drapo


Namedrapo JSON
Version 1.2.2 PyPI version JSON
download
home_pagehttps://github.com/ovinc/drapo
SummaryInteractive features (cursor, draggable lines & rectangles, graphical input, clik-to-make-axes active, etc.) for Matplotlib
upload_time2024-06-11 12:11:39
maintainerNone
docs_urlNone
authorOlivier Vincent
requires_python>=3.6
licenseBSD 3-Clause License
keywords interactive matplotlib draggable cursor line rectangle ginput
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # About

**drapo** (_**dra**ggable **p**lot **o**bjects_) is a Python 3 package that provides a set of interactive graphical objects on Matplotlib figures: draggable line (`Line`), draggable rectangle (`Rect`), moving cursor (`Cursor`), and interactive click to define active figure/axes (`ClickFig`).

Based on these tools, the package also provides graphical input functions for measuring/extracting data interactively from a figure, such as `ginput()` (get location of clicks), `linput()` (extract position from interactive line) and `rinput()` (get region of interest from interactive rectangle).

Matplotlib must be using an interactive backend such as Qt or Tk. In Jupyter, use `%matplotlib qt` or `%matplotlib tk` (or simply `%matplotlib`). The *MacOSX* backend can cause problems (see *Tips and Troubleshooting* below).

### Draggable shapes
- **Line** is a class that creates a draggable line.
- **Rect** is a class that creates a draggable rectangle.

### Moving cursor
- **Cursor** is a class that creates a cursor that follows the mouse

### Graphical input functions
- **ginput** is a function based on the Cursor class that returns position data from clicks/keystrokes.
- **linput** is a function based on the Line class that returns position data of the edges of an interactive line.
- **rinput** is a function based on the Rect class that returns position data delimited by an interactive rectangle.

### Other
- **ClickFig** is a class that activates figures and axes (makes them the current ones) by mouse hovering and clicking.


![](https://raw.githubusercontent.com/ovinc/drapo/master/media/demo.gif)



# Install

```bash
pip install drapo
```


# Quick start

Below is a brief overview on how to use the package contents with the most basic features. For full documentation, see *DOCUMENTATION.md*. For background code and development info, see *DEVELOPMENT.md*.

For a brief demo of various objects:
```bash
python -m drapo.demo
```
(it is possible to specify a backend and/or to turn on/off blitting using the `--backend` and `--blit` flags, see help with `python -m drapo.demo -h`)

To use individual objects and functions:

```python
from drapo import Line, Cursor, Rect, ClickFig, ginput, linput, rinput
```

## Draggable objects

`Line()` creates a line in the current axes of the current figure (creates new figure if none existing) that is draggable by left-clicking on it. Motion is different whether click is done on the line ends or on the line itself. To remove the line, right-click on it.

`Rect()` creates a draggable rectangle in the current or specified figure. Motion is triggered by left-clicking on the edges (lines), vertices (corner points), or in the center (marked by a cross). Right-click to delete.

See documentation for options to change the appearance of these objects.
See ClickFig below to activate axes interactively to be able to create the objects in specific axes as needed.

## Moving cursor

`Cursor()` creates a cursor in the current figure, but contrary to the draggable objects, the cursor is not bound to specific axes. It is however bound to a figure, and will appear on whatever axes the mouse is currently on; it will switch axes if the mouse goes over other axes. No cursor is visible if the mouse is not currently on axes.
- Use <kbd>Alt</kbd> + left/right arrow keys to change color.
- Use <kbd>Alt</kbd> + up/down keys to change thickness.
- Use the <kbd>space</kbd> bar to toggle visibility on/off.

## Graphical input functions

`ginput()` will return the data coordinates (x, y) of one click on any axes of the current figure.
- Use `ginput(n)` to record exactly n data points (returns list of tuples).
- Use `ginput(-1)` for an undefined amount of points.
- Left click or press <kbd>a</kbd> to add point.
- Right click or press <kbd>z</kbd> to remove point.
- Middle click or press <kbd>enter</kbd> to finish input.

`linput()` will instantiate an interactive line and return its position as a tuple ((x1, y1), (x2, y2)) when the <kbd>enter</kbd> key is pressed.

`rinput()` will instantiate an interactive rectangle and return its position as a tuple (xmin, ymin, width, height) when the <kbd>enter</kbd> key is pressed.

## Activate specific figure/axes (ClickFig)

Sometimes the current figure/axes are not the ones where one wants to create the objects. To solve this problem, it is possible to use the ClickFig class.

`ClickFig()` will make all existing figures and axes clickable (hovering the mouse should highlight the fig/ax under it with a light blue color). Simply left-click in the ones you would like to activate. By default, activation stops after one click.

`ClickFig(-1)` will keep all fig/ax active for an undefined amount of clicks. Since ClickFig is non-blocking, this is a way to be able to be able to keep activating axes during a work session, without having to instantiate a ClickFig every time. In this situation, deactivation of the ClickFig is done by right-click.

`ClickFig(highlight=False)` allows not using color highlighting of the fig/ax if it is bothersome.


# Tips and Troubleshooting

## Tips

- When instantiating an object from the command line on an existing figure, Matplotlib figures need to not block the console. For this, use `plt.show(block=False)` when creating the figure.

- If selecting objects is difficult, either increase the `pickersize` property, or upgrade drapo and/or Matplotlib (see *Requirements* below).

## General issues

If encountering problems, try the following:

- Use a different matplotlib backend, e.g. `matplotlib.use('Qt5Agg')`, `matplotlib.use('Qt4Agg')` or `matplotlib.use('TkAgg')`.

- Similarly, in Jupyter, an interactive backend needs to be used, with the command `%matplotlib qt` or `%matplotlib tk` (or simply `%matplotlib`).

- Pass `blit=False` in the argument of any class or function (except ClickFig) to see if the problem comes from the blitting strategy used for fast rendering.

## MacOSX issues

The *MacOSX* backend of Matplotlib seems to cause problems where the figure crashes, or objects get duplicated on the figure, among other things. If encountering problems on a Mac, usually they are solved by either turning off blitting for fast rendering, or by choosing a different backend (see above).

# Requirements

## Packages

- matplotlib
- importlib-metadata
- numpy (optional, only needed to run demos and examples)

**Note**: a bug in drapo < 1.0.5 makes it very difficult to select objects when using Matplotlib <3.3. This has been corrected in drapo >= 1.0.5.

## Python

Python : >= 3.6

# Author

Olivier Vincent

(ovinc.py@gmail.com)

# License

3-Clause BSD (see *LICENSE* file).

BSD 3-Clause License

Copyright (c) 2020, Olivier VINCENT
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
  contributors may be used to endorse or promote products derived from
  this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ovinc/drapo",
    "name": "drapo",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "interactive, matplotlib, draggable, cursor, line, rectangle, ginput",
    "author": "Olivier Vincent",
    "author_email": "ovinc.py@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/9a/bf/dec82788fb6bfe513b51a0b691124fb38c56f65c74ea150eca8ffebf897e/drapo-1.2.2.tar.gz",
    "platform": null,
    "description": "# About\n\n**drapo** (_**dra**ggable **p**lot **o**bjects_) is a Python 3 package that provides a set of interactive graphical objects on Matplotlib figures: draggable line (`Line`), draggable rectangle (`Rect`), moving cursor (`Cursor`), and interactive click to define active figure/axes (`ClickFig`).\n\nBased on these tools, the package also provides graphical input functions for measuring/extracting data interactively from a figure, such as `ginput()` (get location of clicks), `linput()` (extract position from interactive line) and `rinput()` (get region of interest from interactive rectangle).\n\nMatplotlib must be using an interactive backend such as Qt or Tk. In Jupyter, use `%matplotlib qt` or `%matplotlib tk` (or simply `%matplotlib`). The *MacOSX* backend can cause problems (see *Tips and Troubleshooting* below).\n\n### Draggable shapes\n- **Line** is a class that creates a draggable line.\n- **Rect** is a class that creates a draggable rectangle.\n\n### Moving cursor\n- **Cursor** is a class that creates a cursor that follows the mouse\n\n### Graphical input functions\n- **ginput** is a function based on the Cursor class that returns position data from clicks/keystrokes.\n- **linput** is a function based on the Line class that returns position data of the edges of an interactive line.\n- **rinput** is a function based on the Rect class that returns position data delimited by an interactive rectangle.\n\n### Other\n- **ClickFig** is a class that activates figures and axes (makes them the current ones) by mouse hovering and clicking.\n\n\n![](https://raw.githubusercontent.com/ovinc/drapo/master/media/demo.gif)\n\n\n\n# Install\n\n```bash\npip install drapo\n```\n\n\n# Quick start\n\nBelow is a brief overview on how to use the package contents with the most basic features. For full documentation, see *DOCUMENTATION.md*. For background code and development info, see *DEVELOPMENT.md*.\n\nFor a brief demo of various objects:\n```bash\npython -m drapo.demo\n```\n(it is possible to specify a backend and/or to turn on/off blitting using the `--backend` and `--blit` flags, see help with `python -m drapo.demo -h`)\n\nTo use individual objects and functions:\n\n```python\nfrom drapo import Line, Cursor, Rect, ClickFig, ginput, linput, rinput\n```\n\n## Draggable objects\n\n`Line()` creates a line in the current axes of the current figure (creates new figure if none existing) that is draggable by left-clicking on it. Motion is different whether click is done on the line ends or on the line itself. To remove the line, right-click on it.\n\n`Rect()` creates a draggable rectangle in the current or specified figure. Motion is triggered by left-clicking on the edges (lines), vertices (corner points), or in the center (marked by a cross). Right-click to delete.\n\nSee documentation for options to change the appearance of these objects.\nSee ClickFig below to activate axes interactively to be able to create the objects in specific axes as needed.\n\n## Moving cursor\n\n`Cursor()` creates a cursor in the current figure, but contrary to the draggable objects, the cursor is not bound to specific axes. It is however bound to a figure, and will appear on whatever axes the mouse is currently on; it will switch axes if the mouse goes over other axes. No cursor is visible if the mouse is not currently on axes.\n- Use <kbd>Alt</kbd> + left/right arrow keys to change color.\n- Use <kbd>Alt</kbd> + up/down keys to change thickness.\n- Use the <kbd>space</kbd> bar to toggle visibility on/off.\n\n## Graphical input functions\n\n`ginput()` will return the data coordinates (x, y) of one click on any axes of the current figure.\n- Use `ginput(n)` to record exactly n data points (returns list of tuples).\n- Use `ginput(-1)` for an undefined amount of points.\n- Left click or press <kbd>a</kbd> to add point.\n- Right click or press <kbd>z</kbd> to remove point.\n- Middle click or press <kbd>enter</kbd> to finish input.\n\n`linput()` will instantiate an interactive line and return its position as a tuple ((x1, y1), (x2, y2)) when the <kbd>enter</kbd> key is pressed.\n\n`rinput()` will instantiate an interactive rectangle and return its position as a tuple (xmin, ymin, width, height) when the <kbd>enter</kbd> key is pressed.\n\n## Activate specific figure/axes (ClickFig)\n\nSometimes the current figure/axes are not the ones where one wants to create the objects. To solve this problem, it is possible to use the ClickFig class.\n\n`ClickFig()` will make all existing figures and axes clickable (hovering the mouse should highlight the fig/ax under it with a light blue color). Simply left-click in the ones you would like to activate. By default, activation stops after one click.\n\n`ClickFig(-1)` will keep all fig/ax active for an undefined amount of clicks. Since ClickFig is non-blocking, this is a way to be able to be able to keep activating axes during a work session, without having to instantiate a ClickFig every time. In this situation, deactivation of the ClickFig is done by right-click.\n\n`ClickFig(highlight=False)` allows not using color highlighting of the fig/ax if it is bothersome.\n\n\n# Tips and Troubleshooting\n\n## Tips\n\n- When instantiating an object from the command line on an existing figure, Matplotlib figures need to not block the console. For this, use `plt.show(block=False)` when creating the figure.\n\n- If selecting objects is difficult, either increase the `pickersize` property, or upgrade drapo and/or Matplotlib (see *Requirements* below).\n\n## General issues\n\nIf encountering problems, try the following:\n\n- Use a different matplotlib backend, e.g. `matplotlib.use('Qt5Agg')`, `matplotlib.use('Qt4Agg')` or `matplotlib.use('TkAgg')`.\n\n- Similarly, in Jupyter, an interactive backend needs to be used, with the command `%matplotlib qt` or `%matplotlib tk` (or simply `%matplotlib`).\n\n- Pass `blit=False` in the argument of any class or function (except ClickFig) to see if the problem comes from the blitting strategy used for fast rendering.\n\n## MacOSX issues\n\nThe *MacOSX* backend of Matplotlib seems to cause problems where the figure crashes, or objects get duplicated on the figure, among other things. If encountering problems on a Mac, usually they are solved by either turning off blitting for fast rendering, or by choosing a different backend (see above).\n\n# Requirements\n\n## Packages\n\n- matplotlib\n- importlib-metadata\n- numpy (optional, only needed to run demos and examples)\n\n**Note**: a bug in drapo < 1.0.5 makes it very difficult to select objects when using Matplotlib <3.3. This has been corrected in drapo >= 1.0.5.\n\n## Python\n\nPython : >= 3.6\n\n# Author\n\nOlivier Vincent\n\n(ovinc.py@gmail.com)\n\n# License\n\n3-Clause BSD (see *LICENSE* file).\n\nBSD 3-Clause License\n\nCopyright (c) 2020, Olivier VINCENT\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n* Redistributions of source code must retain the above copyright notice, this\n  list of conditions and the following disclaimer.\n\n* Redistributions in binary form must reproduce the above copyright notice,\n  this list of conditions and the following disclaimer in the documentation\n  and/or other materials provided with the distribution.\n\n* Neither the name of the copyright holder nor the names of its\n  contributors may be used to endorse or promote products derived from\n  this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\nFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\nCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\nOR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License",
    "summary": "Interactive features (cursor, draggable lines & rectangles, graphical input, clik-to-make-axes active, etc.) for Matplotlib",
    "version": "1.2.2",
    "project_urls": {
        "Homepage": "https://github.com/ovinc/drapo"
    },
    "split_keywords": [
        "interactive",
        " matplotlib",
        " draggable",
        " cursor",
        " line",
        " rectangle",
        " ginput"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "72c8d11c2715a4caab4c3ab192754a978fb5d3ee4bd057584fc5663e90f5a4fa",
                "md5": "30a7a7ac2221405b7de4c88c59db00a2",
                "sha256": "ef3248545b0af7030e2e208a26afed283b17110f684f2f1fbcfc8821446c5c25"
            },
            "downloads": -1,
            "filename": "drapo-1.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "30a7a7ac2221405b7de4c88c59db00a2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 30160,
            "upload_time": "2024-06-11T12:11:35",
            "upload_time_iso_8601": "2024-06-11T12:11:35.998315Z",
            "url": "https://files.pythonhosted.org/packages/72/c8/d11c2715a4caab4c3ab192754a978fb5d3ee4bd057584fc5663e90f5a4fa/drapo-1.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9abfdec82788fb6bfe513b51a0b691124fb38c56f65c74ea150eca8ffebf897e",
                "md5": "3089423a3e99745cb4b1e4fe76222bbf",
                "sha256": "c5fae4909c7dc464091bfd19d8a4c34df4ee0a8dc1a97376b3a98f3f28473cab"
            },
            "downloads": -1,
            "filename": "drapo-1.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "3089423a3e99745cb4b1e4fe76222bbf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 907529,
            "upload_time": "2024-06-11T12:11:39",
            "upload_time_iso_8601": "2024-06-11T12:11:39.048596Z",
            "url": "https://files.pythonhosted.org/packages/9a/bf/dec82788fb6bfe513b51a0b691124fb38c56f65c74ea150eca8ffebf897e/drapo-1.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-11 12:11:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ovinc",
    "github_project": "drapo",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "drapo"
}
        
Elapsed time: 0.49248s