Skip to content

Commit fc32f93

Browse files
FIX: don't use custom rangeslider anymore (#294)
* update: pre-commit * FIX: no longer use custom RangeSlider * BUILD: update minimum mpl version - for numpy2 compat * ruff stuff * DOC: update sphinx-gallery ignore pattern * MNT: update pre-commit * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * LINT: fix ruff stuff --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ce1195d commit fc32f93

26 files changed

+62
-371
lines changed

.github/workflows/mpl-master-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010

1111
jobs:
1212
test-3x:
13-
name: Matplotlib master
13+
name: Matplotlib nightly
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
matrix:
1818
python-version: ["3.10.x", "3.11.x"]
19-
matplotlib-version: ["3.6", "3.7"]
19+
matplotlib-version: ["3.7", "3.8"]
2020
steps:
2121
- name: Checkout
2222
uses: actions/checkout@v4

.pre-commit-config.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,35 @@ ci:
22
autoupdate_schedule: "quarterly"
33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.4.0
5+
rev: v4.6.0
66
hooks:
77
- id: check-docstring-first
88
- id: end-of-file-fixer
99
- id: trailing-whitespace
1010

1111
- repo: https://github.com/psf/black
12-
rev: 23.3.0
12+
rev: 24.8.0
1313
hooks:
1414
- id: black
1515

1616
- repo: https://github.com/pycqa/isort
17-
rev: 5.12.0
17+
rev: 5.13.2
1818
hooks:
1919
- id: isort
2020

2121
- repo: https://github.com/nbQA-dev/nbQA
22-
rev: 1.7.0
22+
rev: 1.8.7
2323
hooks:
2424
- id: nbqa-black
2525
- id: nbqa-isort
2626

2727
- repo: https://github.com/kynan/nbstripout
28-
rev: 0.6.1
28+
rev: 0.7.1
2929
hooks:
3030
- id: nbstripout
3131

32-
- repo: https://github.com/charliermarsh/ruff-pre-commit
33-
rev: v0.0.256
32+
- repo: https://github.com/astral-sh/ruff-pre-commit
33+
rev: v0.6.4
3434
hooks:
3535
- id: ruff
36-
args: [--fix]
36+
args: [--fix, --exit-non-zero-on-fix]

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"examples_dirs": "examples/gallery", # path to your example scripts
8787
"gallery_dirs": "gallery", # path to where to save gallery generated output
8888
"filename_pattern": "/.*",
89-
"ignore_pattern": "/_.*", # https://www.debuggex.com/
89+
"ignore_pattern": r"_.*", # https://www.debuggex.com/
9090
"image_scrapers": (matplotlib_scraper),
9191
}
9292

@@ -254,4 +254,4 @@ def linkcode_resolve(domain, info):
254254

255255
fn = os.path.relpath(fn, start=os.path.dirname(mpl_inter.__file__))
256256

257-
return f"https://github.com/mpl-extensions/mpl-interactions/blob/main/mpl_interactions/{fn}{linespec}" # noqa: E501
257+
return f"https://github.com/mpl-extensions/mpl-interactions/blob/main/mpl_interactions/{fn}{linespec}"

docs/examples/context.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"id": "9bdc7777-5241-4944-a12b-46f05c894dbe",
5+
"id": "0",
66
"metadata": {},
77
"source": [
88
"# Contextmanager for Controls object\n",
@@ -14,7 +14,7 @@
1414
{
1515
"cell_type": "code",
1616
"execution_count": null,
17-
"id": "4c34e1ff-3ef3-4090-a2bd-7dcb3701e58b",
17+
"id": "1",
1818
"metadata": {
1919
"tags": []
2020
},
@@ -25,7 +25,7 @@
2525
},
2626
{
2727
"cell_type": "markdown",
28-
"id": "28ae4a71-a451-4846-be37-161a42d4a18e",
28+
"id": "2",
2929
"metadata": {},
3030
"source": [
3131
"## Using all params\n",
@@ -63,7 +63,7 @@
6363
{
6464
"cell_type": "code",
6565
"execution_count": null,
66-
"id": "852d736e-2839-4b22-9bd5-1e7b4e35a1d9",
66+
"id": "3",
6767
"metadata": {
6868
"tags": []
6969
},

docs/examples/devlop/devlop-base.ipynb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"outputs": [],
1010
"source": [
1111
"%matplotlib ipympl\n",
12-
"import ipywidgets as widgets\n",
1312
"import matplotlib.pyplot as plt\n",
1413
"import numpy as np\n",
1514
"\n",
@@ -27,8 +26,6 @@
2726
},
2827
"outputs": [],
2928
"source": [
30-
"import matplotlib.pyplot as plt\n",
31-
"import numpy as np\n",
3229
"import xarray as xr\n",
3330
"\n",
3431
"from mpl_interactions import hyperslicer\n",

docs/examples/devlop/devlop-controller.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@
138138
" also allows [None] to grab None of the current params\n",
139139
" to imply that we only want tau from the existing set of commands\n",
140140
" \"\"\"\n",
141-
"\n",
142141
" # make sure keys is a list\n",
143142
" # bc in gogogo_controls it may get added to another list\n",
144143
" if isinstance(key, str):\n",

docs/examples/devlop/devlop-imshow.ipynb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"outputs": [],
88
"source": [
99
"%matplotlib ipympl\n",
10-
"import ipywidgets as widgets\n",
1110
"import matplotlib.pyplot as plt\n",
1211
"import numpy as np\n",
1312
"\n",
@@ -22,7 +21,6 @@
2221
"metadata": {},
2322
"outputs": [],
2423
"source": [
25-
"import numpy as np\n",
2624
"\n",
2725
"parameter1 = np.linspace(-5, 5)\n",
2826
"parameter2 = np.linspace(-5, 5, 25)\n",

docs/examples/devlop/devlop-scatter.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@
137137
"source": [
138138
"import matplotlib.pyplot as plt\n",
139139
"import numpy as np\n",
140-
"from IPython.display import display\n",
141140
"from ipywidgets import widgets\n",
142141
"\n",
143142
"x = np.arange(10)\n",

docs/examples/gallery/heatmap_slicer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
=============
55
66
"""
7+
78
import matplotlib.pyplot as plt
89
import numpy as np
910

docs/examples/gallery/mpl-sliders-same-figure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Demonstration of how to provide a matplotlib slider to prevent
77
the creation of a separate controls figure.
88
"""
9+
910
import matplotlib.pyplot as plt
1011
import numpy as np
1112
from matplotlib.widgets import Slider

docs/examples/heatmap-slicer.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"outputs": [],
1515
"source": [
1616
"%matplotlib widget\n",
17-
"import matplotlib.pyplot as plt\n",
1817
"import numpy as np\n",
1918
"\n",
2019
"from mpl_interactions import heatmap_slicer"

docs/examples/hist.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"outputs": [],
1515
"source": [
1616
"%matplotlib ipympl\n",
17-
"import ipywidgets as widgets\n",
1817
"import matplotlib.pyplot as plt\n",
1918
"import numpy as np\n",
2019
"\n",

docs/examples/image-segmentation.ipynb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"outputs": [],
1717
"source": [
1818
"%matplotlib ipympl\n",
19-
"import matplotlib.cbook as cbook\n",
2019
"import matplotlib.pyplot as plt\n",
2120
"import numpy as np\n",
2221
"\n",
@@ -266,7 +265,6 @@
266265
},
267266
"outputs": [],
268267
"source": [
269-
"from ipywidgets import HBox\n",
270268
"\n",
271269
"grayscale_image = image.mean(axis=-1)\n",
272270
"gray = image_segmenter(grayscale_image, nclasses=3, mask=mask, figsize=(5, 5), cmap=\"gray\")\n",

docs/examples/range-sliders.ipynb

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
]
2424
},
2525
{
26+
"attachments": {},
2627
"cell_type": "markdown",
2728
"metadata": {},
2829
"source": [
@@ -31,8 +32,8 @@
3132
"In order to create a RangeSlider rather than a Slider you prefix the tuples with either `\"r\"` or `\"range\"`, then the rest of the tuple is created according to the rules from converting tuples to sliders. So arrays will remain arrays, or the values will be passed through to np.linspace as appropriate.\n",
3233
"```\n",
3334
"# passed through to np.linspace\n",
34-
"(\"range\", min, max, [step]) \n",
35-
"(\"r\", min, max, [step])\n",
35+
"(\"range\", min, max, [num]) \n",
36+
"(\"r\", min, max, [num])\n",
3637
"\n",
3738
"# array used directly\n",
3839
"(\"range\", np.array)\n",
@@ -93,38 +94,13 @@
9394
]
9495
},
9596
{
97+
"attachments": {},
9698
"cell_type": "markdown",
9799
"metadata": {},
98100
"source": [
99-
"## Using a Matplotlib RangeSlider\n",
101+
"## DEPRECATED+REMOVED - mpl_interactions `RangeSliders`\n",
100102
"\n",
101-
"### But maptlotlib doesn't have range sliders???!?!?\n",
102-
"\n",
103-
"One of the implicit promises of this library is that it will work equally well both in and out of a jupyter notebook. So it leverages ipywidgets when available but otherwise will use matplotlib widgets. However, `ipywidgets` has [`RangeSlider`s](https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html#IntRangeSlider) while Matplotlib does not, so have we broken this contract? Happily the answer is no. RangeSliders are being added to matplolibt in [matplotlib/matplotlib#18829](https://github.com/matplotlib/matplotlib/pull/18829), and in the meantime they are available via {class}`~mpl_interactions.widgets.RangeSlider`."
104-
]
105-
},
106-
{
107-
"cell_type": "code",
108-
"execution_count": null,
109-
"metadata": {},
110-
"outputs": [],
111-
"source": [
112-
"from mpl_interactions.widgets import RangeSlider\n",
113-
"\n",
114-
"fig, axs = plt.subplots(1, 2, figsize=(12, 5))\n",
115-
"\n",
116-
"# plot histogram of pixel intensities\n",
117-
"axs[1].hist(im.flatten(), bins=\"auto\")\n",
118-
"\n",
119-
"# make thresholding slider\n",
120-
"plt.subplots_adjust(bottom=0.25)\n",
121-
"s_ax = plt.axes([0.575, 0.1, 0.25, 0.05])\n",
122-
"slider = RangeSlider(s_ax, \"threshold\", im.min(), im.max(), valinit=(im.min(), im.max()))\n",
123-
"\n",
124-
"# create interactive controls\n",
125-
"ctrls = iplt.imshow(im, vmin_vmax=slider, ax=axs[0])\n",
126-
"iplt.axvline(ctrls[\"vmin\"], ax=axs[1], c=\"k\")\n",
127-
"iplt.axvline(ctrls[\"vmax\"], ax=axs[1], c=\"k\")"
103+
"Until version `3.4` `matplotlib` did not have a RangeSlider widget so this library provided one. Since `mpl-interactions` now depends on `matplotlib > 3.4` the `mpl-interactions` RangeSlider is no longer available.\n"
128104
]
129105
}
130106
],

docs/examples/rossler-attractor.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"outputs": [],
2121
"source": [
2222
"%matplotlib ipympl\n",
23-
"from functools import lru_cache\n",
2423
"\n",
2524
"import ipywidgets as widgets\n",
2625
"import matplotlib.pyplot as plt\n",

docs/examples/scalar-arguments.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
"metadata": {},
9797
"outputs": [],
9898
"source": [
99-
"from mpl_interactions.controller import Controls\n",
10099
"\n",
101100
"# create the controls object\n",
102101
"ctrls = Controls(size=(10, 1000))\n",

docs/examples/scatter-selector.ipynb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@
3131
"%matplotlib ipympl\n",
3232
"import pickle\n",
3333
"\n",
34-
"import ipywidgets as widgets\n",
3534
"import matplotlib.pyplot as plt\n",
3635
"import numpy as np\n",
3736
"\n",
3837
"import mpl_interactions.ipyplot as iplt\n",
3938
"from mpl_interactions import indexer, panhandler, zoom_factory\n",
40-
"from mpl_interactions.utils import indexer\n",
4139
"from mpl_interactions.widgets import scatter_selector_index"
4240
]
4341
},
@@ -58,8 +56,6 @@
5856
"metadata": {},
5957
"outputs": [],
6058
"source": [
61-
"import pickle\n",
62-
"\n",
6359
"with open(\"data/stock-metadata.pickle\", \"rb\") as f:\n",
6460
" meta = pickle.load(f)\n",
6561
"prices = np.load(\"data/stock-prices.npz\")[\"prices\"]\n",
@@ -169,6 +165,7 @@
169165
"# Download the data from https://www.kaggle.com/camnugent/sandp500\n",
170166
"# and save it into a folder named `data`\n",
171167
"import glob\n",
168+
"import pickle\n",
172169
"\n",
173170
"test = np.loadtxt(\"data/A_data.csv\", delimiter=\",\", skiprows=1, usecols=1)\n",
174171
"sp500_glob = glob.glob(\n",
@@ -184,7 +181,7 @@
184181
" try:\n",
185182
" prices[i] = np.loadtxt(f, delimiter=\",\", skiprows=1, usecols=1)\n",
186183
" prices_good.append(True)\n",
187-
" except:\n",
184+
" except: # noqa\n",
188185
" fails.append(fname.split(\"_\")[0])\n",
189186
" prices_good.append(False)\n",
190187
" pass\n",
@@ -199,19 +196,18 @@
199196
"good_names = []\n",
200197
"primary = []\n",
201198
"secondary = []\n",
202-
"good_idx = np.zeros(real_names.shape[0], dtype=bool)\n",
203-
"for i, name in enumerate(real_names):\n",
199+
"good_idx = np.zeros(arr.shape[0], dtype=bool)\n",
200+
"for i, name in enumerate(arr):\n",
204201
" try:\n",
205202
" info = name_dict[name]\n",
206203
" good_idx[i] = True\n",
207204
" good_names.append(info[0])\n",
208205
" primary.append(info[1])\n",
209206
" secondary.append(info[2])\n",
210-
" except:\n",
207+
" except KeyError:\n",
211208
" pass\n",
212209
"psector_dict = {val: i for i, val in enumerate(np.unique(primary))}\n",
213210
"data_colors = np.array([psector_dict[val] for val in primary], dtype=int)\n",
214-
"import pickle\n",
215211
"\n",
216212
"meta = {\n",
217213
" \"good_idx\": good_idx,\n",
@@ -226,7 +222,7 @@
226222
],
227223
"metadata": {
228224
"kernelspec": {
229-
"display_name": "Python 3 (ipykernel)",
225+
"display_name": "mpl-ext-dev",
230226
"language": "python",
231227
"name": "python3"
232228
},
@@ -241,6 +237,11 @@
241237
"nbconvert_exporter": "python",
242238
"pygments_lexer": "ipython3",
243239
"version": "3.11.0"
240+
},
241+
"vscode": {
242+
"interpreter": {
243+
"hash": "55dd65db90870e4ef86f9b4099f0eeaeed6e43259b5e360e26f77b1862bc7b1c"
244+
}
244245
}
245246
},
246247
"nbformat": 4,

docs/examples/scatter.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
"outputs": [],
1515
"source": [
1616
"%matplotlib ipympl\n",
17-
"import ipywidgets as widgets\n",
1817
"import matplotlib.pyplot as plt\n",
1918
"import numpy as np\n",
2019
"import pandas as pd\n",
21-
"from matplotlib.colors import TABLEAU_COLORS, XKCD_COLORS, to_rgba_array\n",
20+
"from matplotlib.colors import TABLEAU_COLORS\n",
2221
"\n",
2322
"import mpl_interactions.ipyplot as iplt"
2423
]

0 commit comments

Comments
 (0)