Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linting #271

Merged
merged 9 commits into from
Apr 13, 2023
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,4 @@ _version.py

# mpl testing
result_images/
docs/examples/devlop
34 changes: 8 additions & 26 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ ci:
autoupdate_schedule: "quarterly"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: check-docstring-first
- id: end-of-file-fixer
- id: trailing-whitespace

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

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

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.5.2
rev: 1.7.0
hooks:
- id: nbqa-black
- id: nbqa-isort
Expand All @@ -29,26 +29,8 @@ repos:
hooks:
- id: nbstripout

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.0
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.256
hooks:
- id: prettier

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies: [flake8-typing-imports==1.7.0]

- repo: https://github.com/PyCQA/autoflake
rev: v1.6.1
hooks:
- id: autoflake
args:
[
"--exclude=mpl_interactions/ipyplot.py",
"--in-place",
"--remove-all-unused-imports",
"--ignore-init-module-imports",
"--remove-unused-variables",
]
- id: ruff
args: [--fix]
4 changes: 4 additions & 0 deletions docs/examples/custom-callbacks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"outputs": [],
"source": [
"# define the function\n",
"\n",
"\n",
"def f(x, tau, beta):\n",
" return np.sin(x * tau) * beta\n",
"\n",
Expand Down Expand Up @@ -158,6 +160,8 @@
"# attach a custom callback\n",
"\n",
"# if running from a script you can just delete the widgets.Output and associated code\n",
"\n",
"\n",
"def my_callback(tau, beta):\n",
" if tau < 7.5:\n",
" ax.tick_params(axis=\"x\", colors=\"red\")\n",
Expand Down
171 changes: 168 additions & 3 deletions docs/examples/devlop/devlop-base.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"%matplotlib ipympl\n",
Expand All @@ -16,11 +18,174 @@
"import mpl_interactions.ipyplot as iplt\n",
"from mpl_interactions import *"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"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",
"\n",
"arr = np.zeros([10, 150, 200])\n",
"arr[:, 50:100, 50:150] = 1\n",
"\n",
"arr_xr = xr.DataArray(arr, dims=(\"whatever\", \"y\", \"x\"))\n",
"\n",
"fig, axs = plt.subplots(2, 2)\n",
"\n",
"im_upper = axs[0, 0].imshow(arr[0], origin=\"upper\")\n",
"axs[0, 0].set_title(\"imshow - upper\")\n",
"axs[0, 1].set_title(\"hypeslicer - upper\")\n",
"x = np.linspace(0, 100)\n",
"axs[0, 0].scatter(x, x)\n",
"axs[0, 1].scatter(x, x)\n",
"ctrls = hyperslicer(arr_xr, ax=axs[0, 1], origin=\"upper\")\n",
"\n",
"im_lower = axs[1, 0].imshow(arr[0], origin=\"lower\")\n",
"axs[1, 0].set_title(\"imshow - lower\")\n",
"x = np.linspace(0, 100)\n",
"axs[1, 0].scatter(x, x)\n",
"axs[1, 1].scatter(x, x)\n",
"axs[1, 1].set_title(\"hyperslicer - lower\")\n",
"ctrls2 = hyperslicer(arr_xr, ax=axs[1, 1], origin=\"lower\")\n",
"plt.tight_layout()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"axs.flatten()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"for ax in axs.flatten():\n",
" print(ax.get_xlim())\n",
" print(ax.get_ylim())\n",
" print(\"------------\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"im_lower.get_extent()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"def hyperslicer_1d(arr, split_dim=None, **kwargs):\n",
" arr = np.asanyarray(arr)\n",
" if split_dim == -1 or split_dim == arr.ndim:\n",
" raise ValueError(\"nope split_dim must not be the last axis\")\n",
" axes = {}\n",
" for i, s in enumerate(arr.shape[:-1]):\n",
" axes[f\"axis_{i}\"] = np.arange(s)\n",
" slices = [0 for i in range(arr.ndim - 1)]\n",
" slices.append(slice(None))\n",
"\n",
" def picker(**kwargs):\n",
" for i in range(arr.ndim - 1):\n",
" slices[i] = int(kwargs[f\"axis_{i}\"])\n",
" if split_dim is not None:\n",
" slices[split_dim] = slice(None)\n",
" return arr[tuple(slices)].T\n",
"\n",
" ctrls = kwargs.get(\"controls\", None)\n",
" if ctrls:\n",
" return iplt.plot(picker, **kwargs)\n",
" else:\n",
" return iplt.plot(picker, **axes, **kwargs)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"arr1 = np.random.rand(11, 1340)\n",
"arr2 = np.random.rand(11, 1340)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"plt.subplots()\n",
"ctrls = hyperslicer_1d(arr1)\n",
"hyperslicer_1d(arr2, controls=ctrls)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"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",
"\n",
"arr = np.zeros([10, 150, 200])\n",
"arr[:, 50:100, 50:150] = 1\n",
"\n",
"\n",
"fig, axs = plt.subplots(1, 2)\n",
"\n",
"with hyperslicer(arr, ax=axs[0]) as ctrls:\n",
" hyperslicer(arr, ax=axs[1])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -34,7 +199,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.0"
"version": "3.11.0"
}
},
"nbformat": 4,
Expand Down
2 changes: 0 additions & 2 deletions docs/examples/devlop/devlop-controller.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@
" )\n",
"\n",
" def update(params, indices):\n",
"\n",
" # update plot\n",
" for i, f in enumerate(funcs):\n",
" if x is not None and not indexed_x:\n",
Expand Down Expand Up @@ -379,7 +378,6 @@
"\n",
" lines = []\n",
" for i, f in enumerate(funcs):\n",
"\n",
" if x is not None and not indexed_x:\n",
" lines.append(ax.plot(x, f(x, **params), **plot_kwargs[i])[0])\n",
" elif indexed_x:\n",
Expand Down
7 changes: 0 additions & 7 deletions docs/examples/hyperslicer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,6 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
Expand Down
7 changes: 0 additions & 7 deletions docs/examples/rossler-attractor.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,6 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
Expand Down
7 changes: 0 additions & 7 deletions docs/examples/scatter-selector.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,6 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
Expand Down
7 changes: 0 additions & 7 deletions docs/examples/text-annotations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,6 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
Expand Down
4 changes: 4 additions & 0 deletions docs/examples/usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
"outputs": [],
"source": [
"# define the function\n",
"\n",
"\n",
"def f(x, tau, beta):\n",
" return np.sin(x * tau) * x**beta\n",
"\n",
Expand Down Expand Up @@ -453,6 +455,8 @@
"\n",
"iplt.title(\"the value of tau is: {tau:.2f}\", controls=controls[\"tau\"])\n",
"# you can still use plt commands if this is the active figure\n",
"\n",
"\n",
"def ylabel(tau):\n",
" return f\"tau/2 is {np.round(tau/2,3)}\"\n",
"\n",
Expand Down
1 change: 0 additions & 1 deletion mpl_interactions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from ._version import __version__
except ImportError:
__version__ = "unkown"
from .deprecations import mpl_interactions_DeprecationWarning
from .generic import *
from .helpers import *
from .pyplot import *
Expand Down
Loading