Skip to content

Commit

Permalink
FIX: don't use custom rangeslider anymore (#294)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
ianhi and pre-commit-ci[bot] authored Sep 10, 2024
1 parent ce1195d commit fc32f93
Show file tree
Hide file tree
Showing 26 changed files with 62 additions and 371 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mpl-master-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

jobs:
test-3x:
name: Matplotlib master
name: Matplotlib nightly
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
python-version: ["3.10.x", "3.11.x"]
matplotlib-version: ["3.6", "3.7"]
matplotlib-version: ["3.7", "3.8"]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@ ci:
autoupdate_schedule: "quarterly"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: check-docstring-first
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 24.8.0
hooks:
- id: black

- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.7.0
rev: 1.8.7
hooks:
- id: nbqa-black
- id: nbqa-isort

- repo: https://github.com/kynan/nbstripout
rev: 0.6.1
rev: 0.7.1
hooks:
- id: nbstripout

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.256
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.4
hooks:
- id: ruff
args: [--fix]
args: [--fix, --exit-non-zero-on-fix]
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"examples_dirs": "examples/gallery", # path to your example scripts
"gallery_dirs": "gallery", # path to where to save gallery generated output
"filename_pattern": "/.*",
"ignore_pattern": "/_.*", # https://www.debuggex.com/
"ignore_pattern": r"_.*", # https://www.debuggex.com/
"image_scrapers": (matplotlib_scraper),
}

Expand Down Expand Up @@ -254,4 +254,4 @@ def linkcode_resolve(domain, info):

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

return f"https://github.com/mpl-extensions/mpl-interactions/blob/main/mpl_interactions/{fn}{linespec}" # noqa: E501
return f"https://github.com/mpl-extensions/mpl-interactions/blob/main/mpl_interactions/{fn}{linespec}"
8 changes: 4 additions & 4 deletions docs/examples/context.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "9bdc7777-5241-4944-a12b-46f05c894dbe",
"id": "0",
"metadata": {},
"source": [
"# Contextmanager for Controls object\n",
Expand All @@ -14,7 +14,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "4c34e1ff-3ef3-4090-a2bd-7dcb3701e58b",
"id": "1",
"metadata": {
"tags": []
},
Expand All @@ -25,7 +25,7 @@
},
{
"cell_type": "markdown",
"id": "28ae4a71-a451-4846-be37-161a42d4a18e",
"id": "2",
"metadata": {},
"source": [
"## Using all params\n",
Expand Down Expand Up @@ -63,7 +63,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "852d736e-2839-4b22-9bd5-1e7b4e35a1d9",
"id": "3",
"metadata": {
"tags": []
},
Expand Down
3 changes: 0 additions & 3 deletions docs/examples/devlop/devlop-base.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"outputs": [],
"source": [
"%matplotlib ipympl\n",
"import ipywidgets as widgets\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
Expand All @@ -27,8 +26,6 @@
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import xarray as xr\n",
"\n",
"from mpl_interactions import hyperslicer\n",
Expand Down
1 change: 0 additions & 1 deletion docs/examples/devlop/devlop-controller.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@
" also allows [None] to grab None of the current params\n",
" to imply that we only want tau from the existing set of commands\n",
" \"\"\"\n",
"\n",
" # make sure keys is a list\n",
" # bc in gogogo_controls it may get added to another list\n",
" if isinstance(key, str):\n",
Expand Down
2 changes: 0 additions & 2 deletions docs/examples/devlop/devlop-imshow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"outputs": [],
"source": [
"%matplotlib ipympl\n",
"import ipywidgets as widgets\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
Expand All @@ -22,7 +21,6 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"parameter1 = np.linspace(-5, 5)\n",
"parameter2 = np.linspace(-5, 5, 25)\n",
Expand Down
1 change: 0 additions & 1 deletion docs/examples/devlop/devlop-scatter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from IPython.display import display\n",
"from ipywidgets import widgets\n",
"\n",
"x = np.arange(10)\n",
Expand Down
1 change: 1 addition & 0 deletions docs/examples/gallery/heatmap_slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
=============
"""

import matplotlib.pyplot as plt
import numpy as np

Expand Down
1 change: 1 addition & 0 deletions docs/examples/gallery/mpl-sliders-same-figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Demonstration of how to provide a matplotlib slider to prevent
the creation of a separate controls figure.
"""

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.widgets import Slider
Expand Down
1 change: 0 additions & 1 deletion docs/examples/heatmap-slicer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"outputs": [],
"source": [
"%matplotlib widget\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"from mpl_interactions import heatmap_slicer"
Expand Down
1 change: 0 additions & 1 deletion docs/examples/hist.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"outputs": [],
"source": [
"%matplotlib ipympl\n",
"import ipywidgets as widgets\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
Expand Down
2 changes: 0 additions & 2 deletions docs/examples/image-segmentation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"outputs": [],
"source": [
"%matplotlib ipympl\n",
"import matplotlib.cbook as cbook\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
Expand Down Expand Up @@ -266,7 +265,6 @@
},
"outputs": [],
"source": [
"from ipywidgets import HBox\n",
"\n",
"grayscale_image = image.mean(axis=-1)\n",
"gray = image_segmenter(grayscale_image, nclasses=3, mask=mask, figsize=(5, 5), cmap=\"gray\")\n",
Expand Down
36 changes: 6 additions & 30 deletions docs/examples/range-sliders.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -31,8 +32,8 @@
"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",
"```\n",
"# passed through to np.linspace\n",
"(\"range\", min, max, [step]) \n",
"(\"r\", min, max, [step])\n",
"(\"range\", min, max, [num]) \n",
"(\"r\", min, max, [num])\n",
"\n",
"# array used directly\n",
"(\"range\", np.array)\n",
Expand Down Expand Up @@ -93,38 +94,13 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using a Matplotlib RangeSlider\n",
"## DEPRECATED+REMOVED - mpl_interactions `RangeSliders`\n",
"\n",
"### But maptlotlib doesn't have range sliders???!?!?\n",
"\n",
"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`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from mpl_interactions.widgets import RangeSlider\n",
"\n",
"fig, axs = plt.subplots(1, 2, figsize=(12, 5))\n",
"\n",
"# plot histogram of pixel intensities\n",
"axs[1].hist(im.flatten(), bins=\"auto\")\n",
"\n",
"# make thresholding slider\n",
"plt.subplots_adjust(bottom=0.25)\n",
"s_ax = plt.axes([0.575, 0.1, 0.25, 0.05])\n",
"slider = RangeSlider(s_ax, \"threshold\", im.min(), im.max(), valinit=(im.min(), im.max()))\n",
"\n",
"# create interactive controls\n",
"ctrls = iplt.imshow(im, vmin_vmax=slider, ax=axs[0])\n",
"iplt.axvline(ctrls[\"vmin\"], ax=axs[1], c=\"k\")\n",
"iplt.axvline(ctrls[\"vmax\"], ax=axs[1], c=\"k\")"
"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"
]
}
],
Expand Down
1 change: 0 additions & 1 deletion docs/examples/rossler-attractor.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"outputs": [],
"source": [
"%matplotlib ipympl\n",
"from functools import lru_cache\n",
"\n",
"import ipywidgets as widgets\n",
"import matplotlib.pyplot as plt\n",
Expand Down
1 change: 0 additions & 1 deletion docs/examples/scalar-arguments.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
"metadata": {},
"outputs": [],
"source": [
"from mpl_interactions.controller import Controls\n",
"\n",
"# create the controls object\n",
"ctrls = Controls(size=(10, 1000))\n",
Expand Down
21 changes: 11 additions & 10 deletions docs/examples/scatter-selector.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@
"%matplotlib ipympl\n",
"import pickle\n",
"\n",
"import ipywidgets as widgets\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import mpl_interactions.ipyplot as iplt\n",
"from mpl_interactions import indexer, panhandler, zoom_factory\n",
"from mpl_interactions.utils import indexer\n",
"from mpl_interactions.widgets import scatter_selector_index"
]
},
Expand All @@ -58,8 +56,6 @@
"metadata": {},
"outputs": [],
"source": [
"import pickle\n",
"\n",
"with open(\"data/stock-metadata.pickle\", \"rb\") as f:\n",
" meta = pickle.load(f)\n",
"prices = np.load(\"data/stock-prices.npz\")[\"prices\"]\n",
Expand Down Expand Up @@ -169,6 +165,7 @@
"# Download the data from https://www.kaggle.com/camnugent/sandp500\n",
"# and save it into a folder named `data`\n",
"import glob\n",
"import pickle\n",
"\n",
"test = np.loadtxt(\"data/A_data.csv\", delimiter=\",\", skiprows=1, usecols=1)\n",
"sp500_glob = glob.glob(\n",
Expand All @@ -184,7 +181,7 @@
" try:\n",
" prices[i] = np.loadtxt(f, delimiter=\",\", skiprows=1, usecols=1)\n",
" prices_good.append(True)\n",
" except:\n",
" except: # noqa\n",
" fails.append(fname.split(\"_\")[0])\n",
" prices_good.append(False)\n",
" pass\n",
Expand All @@ -199,19 +196,18 @@
"good_names = []\n",
"primary = []\n",
"secondary = []\n",
"good_idx = np.zeros(real_names.shape[0], dtype=bool)\n",
"for i, name in enumerate(real_names):\n",
"good_idx = np.zeros(arr.shape[0], dtype=bool)\n",
"for i, name in enumerate(arr):\n",
" try:\n",
" info = name_dict[name]\n",
" good_idx[i] = True\n",
" good_names.append(info[0])\n",
" primary.append(info[1])\n",
" secondary.append(info[2])\n",
" except:\n",
" except KeyError:\n",
" pass\n",
"psector_dict = {val: i for i, val in enumerate(np.unique(primary))}\n",
"data_colors = np.array([psector_dict[val] for val in primary], dtype=int)\n",
"import pickle\n",
"\n",
"meta = {\n",
" \"good_idx\": good_idx,\n",
Expand All @@ -226,7 +222,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "mpl-ext-dev",
"language": "python",
"name": "python3"
},
Expand All @@ -241,6 +237,11 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
},
"vscode": {
"interpreter": {
"hash": "55dd65db90870e4ef86f9b4099f0eeaeed6e43259b5e360e26f77b1862bc7b1c"
}
}
},
"nbformat": 4,
Expand Down
3 changes: 1 addition & 2 deletions docs/examples/scatter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
"outputs": [],
"source": [
"%matplotlib ipympl\n",
"import ipywidgets as widgets\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd\n",
"from matplotlib.colors import TABLEAU_COLORS, XKCD_COLORS, to_rgba_array\n",
"from matplotlib.colors import TABLEAU_COLORS\n",
"\n",
"import mpl_interactions.ipyplot as iplt"
]
Expand Down
Loading

0 comments on commit fc32f93

Please sign in to comment.