Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Changelog
Versions follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html) (`<major>`.`<minor>`.`<patch>`)

## [v1.2.0]
### Changed
* Windowing helper utilities now merge user-specified axes/plot kwargs with defaults, preferring user inputs
* (Internal) Snap checking now utilizes axes native data rather than having to special case multiple numpy datatypes to prevent errors
* Add `NaN` awareness to prevent unexpected behavior when working with datasets containing gaps
* Expand & normalize handling of types expected for xy data, `position`, and `window_width`; all types that matplotlib can plot should also be meaningfully supported

### Fixed
* Fix `DragRect` completely ignoring user-specified redraw callbacks
* Fix `FlexibleRect` not calling the redraw callback when respanning
* Fix incorrect resizing of `DragRect` on axis limit change
* Fix `DragLine` accidentally validating `snap_to` against xdata for vertical lines

## [v1.1.0]
### Changed
* #9 Dragging is now inhibited while another widget has the canvas locked (e.g. zooming/panning)
Expand Down
56 changes: 31 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,44 @@ Draggable data windowing for matplotlib plots. Inspired by the adventures of pas
## Interface
For most use cases, interaction with this library is done via the helper wrappers in `matplotlib_window.window`. These functions will accept the user data and build the plots directly for windowing.

#### Units
In addition to numeric data, plotted data and window `position`/`window_width` values may be of any type supported by matplotlib's unit conversion (e.g. `datetime`/`timedelta`, or NumPy's `datetime64`/`timedelta64`).

Returned window bounds are always provided in the axes' native float units; for datetime data these can be converted back to datetimes using [`matplotlib.dates.num2date`](https://matplotlib.org/stable/api/dates_api.html#matplotlib.dates.num2date).

### `fixed_window`
Plot the provided data & build a draggable fixed-width window to select bounds of interest; the x-locations of the edges of the window are returned once the figure window is closed.

#### Parameters
| Parameter | Description | Type | Default |
|----------------|-----------------------------------------------------------------------------|------------------------|------------------|
| `x_data` | x data values to plot | `Sequence[int\|float]` | Required |
| `y_data` | y data values to plot | `Sequence[int\|float]` | Required |
| `position` | x-coordinate of the left edge of the window | `int\|float` | Required |
| `window_width` | Width, along the x-axis, of the draggable window | `int\|float` | Required |
| `snap_to_data` | Prevent dragging of the window beyond beyond the bounds of the plotted data | `bool` | `True` |
| `axes_kwargs` | Optional kwargs to pass to the `Axes` constructor<sup>1</sup> | `dict[str, Any]` | `{"title": ...}` |
| `plot_kwargs` | Optional kwargs to pass to the plotting call<sup>2</sup> | `dict[str, Any]` | `{}` |

1. kwargs are passed directly to the `Axes` constructor, see the [`matplotlib.axes.Axes` documentation](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes) for supported arguments.
2. kwargs are passed directly to the plotting call, see the [`matplotlib.pyplot.plot` documentation](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html) for supported arguments.
| Parameter | Description | Type | Default |
|----------------|----------------------------------------------------------------------|------------------|------------------|
| `x_data` | x data values to plot | See: Note 1 | Required |
| `y_data` | y data values to plot | See: Note 1 | Required |
| `position` | x-coordinate of the left edge of the window | See: Note 1 | Required |
| `window_width` | Width, along the x-axis, of the draggable window | See: Note 1 | Required |
| `snap_to_data` | Prevent dragging of the window beyond the bounds of the plotted data | `bool` | `True` |
| `axes_kwargs` | Optional kwargs to pass to the `Axes` setter<sup>2</sup> | `dict[str, Any]` | `{"title": ...}` |
| `plot_kwargs` | Optional kwargs to pass to the plotting call<sup>3</sup> | `dict[str, Any]` | `{}` |

1. `int|float`, or any type supported by matplotlib's unit conversion, see: [Units](#units)
2. kwargs are passed directly to the `Axes` using `Axes.set()`, see the [`matplotlib.axes.Axes` documentation](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes) for supported arguments.
3. kwargs are passed directly to the plotting call, see the [`matplotlib.pyplot.plot` documentation](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html) for supported arguments.

### `flexible_window`
Plot the provided data & build a flexible-width window to select bounds of interest; the x-locations of the edges of the window are returned once the figure window is closed.

#### Parameters
| Parameter | Description | Type | Default |
|-------------------|-----------------------------------------------------------------------------|------------------------|------------------|
| `x_data` | x data values to plot | `Sequence[int\|float]` | Required |
| `y_data` | y data values to plot | `Sequence[int\|float]` | Required |
| `position` | x-coordinate of the left edge of the window | `int\|float` | Required |
| `window_width` | Starting width, along the x-axis, of the flexible window | `int\|float` | Required |
| `snap_to_data` | Prevent dragging of the window beyond beyond the bounds of the plotted data | `bool` | `True` |
| `allow_face_drag` | Allow dragging of the window using its face<sup>1</sup> | `bool` | `False` |
| `axes_kwargs` | Optional kwargs to pass to the `Axes` constructor<sup>2</sup> | `dict[str, Any]` | `{"title": ...}` |
| `plot_kwargs` | Optional kwargs to pass to the plotting call<sup>3</sup> | `dict[str, Any]` | `{}` |

1. Currently not implemented
2. kwargs are passed directly to the `Axes` constructor, see the [`matplotlib.axes.Axes` documentation](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes) for supported arguments.
| Parameter | Description | Type | Default |
|-------------------|----------------------------------------------------------------------|----------------- |------------------|
| `x_data` | x data values to plot | See: Note 1 | Required |
| `y_data` | y data values to plot | See: Note 1 | Required |
| `position` | x-coordinate of the left edge of the window | See: Note 1 | Required |
| `window_width` | Starting width, along the x-axis, of the flexible window | See: Note 1 | Required |
| `snap_to_data` | Prevent dragging of the window beyond the bounds of the plotted data | `bool` | `True` |
| `allow_face_drag` | Allow dragging of the window using its face | `bool` | `False` |
| `axes_kwargs` | Optional kwargs to pass to the `Axes` setter<sup>3</sup> | `dict[str, Any]` | `{"title": ...}` |
| `plot_kwargs` | Optional kwargs to pass to the plotting call<sup>4</sup> | `dict[str, Any]` | `{}` |

1. `int|float`, or any type supported by matplotlib's unit conversion, see: [Units](#units)
2. kwargs are passed directly to the `Axes` using `Axes.set()`, see the [`matplotlib.axes.Axes` documentation](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes) for supported arguments.
3. kwargs are passed directly to the plotting call, see the [`matplotlib.pyplot.plot` documentation](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html) for supported arguments.
Loading
Loading