Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ad86b38

Browse files
committed
Merge branch 'main' into add-feature-histogram
2 parents 20300a4 + 3a8261a commit ad86b38

27 files changed

+250
-93
lines changed

.github/workflows/docs.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
name: Build docs
22

33
on:
4+
45
pull_request:
56
branches:
67
- main
8+
push:
9+
branches:
10+
- main
11+
tags:
12+
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
713

814
jobs:
915
build-docs:
@@ -40,7 +46,7 @@ jobs:
4046
name: Upload docs to GitHub pages
4147
runs-on: ubuntu-latest
4248
needs: build-docs
43-
if: github.event_name == 'push' && github.ref_name == 'main'
49+
if: contains(github.ref, 'tags')
4450
steps:
4551
- uses: actions/checkout@v3
4652
- uses: actions/download-artifact@v3
@@ -52,4 +58,4 @@ jobs:
5258
with:
5359
folder: html
5460
ssh-key: ${{ secrets.DEPLOY_KEY }}
55-
repository-name: dstansby/napari-matplotlib-docs
61+
repository-name: napari-matplotlib/napari-matplotlib.github.io

.github/workflows/test_and_deploy.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,24 @@ jobs:
7373
needs: [test]
7474
runs-on: ubuntu-latest
7575
if: contains(github.ref, 'tags')
76+
environment: pypi-deploy
77+
permissions:
78+
id-token: write
7679
steps:
7780
- uses: actions/checkout@v2
7881
- name: Set up Python
7982
uses: actions/setup-python@v2
8083
with:
8184
python-version: "3.x"
82-
- name: Install dependencies
85+
- name: Install build
8386
run: |
8487
python -m pip install --upgrade pip
85-
pip install -U setuptools setuptools_scm wheel twine build
86-
- name: Build and publish
87-
env:
88-
TWINE_USERNAME: __token__
89-
TWINE_PASSWORD: ${{ secrets.TWINE_API_KEY }}
88+
python -m pip install --upgrade build
89+
90+
- name: Build package
9091
run: |
9192
git tag
9293
python -m build .
93-
twine upload dist/*
94+
95+
- name: Publish package
96+
uses: pypa/gh-action-pypi-publish@release/v1

.pre-commit-config.yaml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,8 @@ repos:
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
88

9-
- repo: https://github.com/asottile/setup-cfg-fmt
10-
rev: v2.3.0
11-
hooks:
12-
- id: setup-cfg-fmt
13-
149
- repo: https://github.com/psf/black
15-
rev: 23.3.0
10+
rev: 23.7.0
1611
hooks:
1712
- id: black
1813

@@ -22,14 +17,14 @@ repos:
2217
- id: napari-plugin-checks
2318

2419
- repo: https://github.com/pre-commit/mirrors-mypy
25-
rev: v1.3.0
20+
rev: v1.5.1
2621
hooks:
2722
- id: mypy
2823
additional_dependencies: [numpy, matplotlib]
2924

30-
- repo: https://github.com/charliermarsh/ruff-pre-commit
25+
- repo: https://github.com/astral-sh/ruff-pre-commit
3126
# Ruff version.
32-
rev: 'v0.0.272'
27+
rev: 'v0.0.285'
3328
hooks:
3429
- id: ruff
3530

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
[![Python Version](https://img.shields.io/pypi/pyversions/napari-matplotlib.svg?color=green)](https://python.org)
66
[![tests](https://github.com/matplotlib/napari-matplotlib/workflows/tests/badge.svg)](https://github.com/matplotlib/napari-matplotlib/actions)
77
[![codecov](https://codecov.io/gh/matplotlib/napari-matplotlib/branch/main/graph/badge.svg)](https://codecov.io/gh/matplotlib/napari-matplotlib)
8-
[![readthedocs](https://readthedocs.org/projects/napari-matplotlib/badge/?version=latest)](https://napari-matplotlib.readthedocs.io/en/latest/)
98
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/matplotlib/pytest-mpl/master.svg)](https://results.pre-commit.ci/latest/github/matplotlib/pytest-mpl/master)
109
[![napari hub](https://img.shields.io/endpoint?url=https://api.napari-hub.org/shields/napari-matplotlib)](https://napari-hub.org/plugins/napari-matplotlib)
1110

docs/_static/hist.png

1.06 MB
Loading

docs/_static/logo.png

51.4 KB
Loading

docs/changelog.rst

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,40 @@
11
Changelog
22
=========
3+
1.0.3
4+
-----
5+
Changes
6+
~~~~~~~
7+
- The slice widget is now limited to slicing along the x/y dimensions. Support
8+
for slicing along z has been removed for now to make the code simpler.
9+
- The slice widget now uses a slider to select the slice value.
10+
11+
Bug fixes
12+
~~~~~~~~~
13+
- Fixed creating 1D slices of 2D images.
14+
- Removed the limitation that only the first 99 indices could be sliced using
15+
the slice widget.
16+
17+
1.0.2
18+
-----
19+
Bug fixes
20+
~~~~~~~~~
21+
- A full dataset is no longer read into memory when using ``HistogramWidget``.
22+
Only the current slice is loaded.
23+
- Fixed compatibility with napari 0.4.18.
24+
25+
Changes
26+
~~~~~~~
27+
- Histogram bin limits are now caclualted from the slice being histogrammed, and
28+
not the whole dataset. This is as a result of the above bug fix.
29+
30+
1.0.1
31+
-----
32+
Bug fixes
33+
~~~~~~~~~
34+
- Pinned that maximum version of `napari` to 0.4.17, since ``napari-matplotlib``
35+
does not yet work with ``napari`` 0.4.18.
336

4-
0.3.0
37+
1.0.0
538
-----
639

740
New features
@@ -15,6 +48,8 @@ Visual improvements
1548
~~~~~~~~~~~~~~~~~~~
1649
- The background of ``napari-matplotlib`` figures and axes is now transparent, and the text and axis colour respects the ``napari`` theme.
1750
- The icons in the Matplotlib toolbar are now the same size as icons in the napari window.
51+
- Custom style sheets can now be set to customise plots. See the user guide
52+
for more information.
1853

1954
Changes
2055
~~~~~~~

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
# a list of builtin themes.
8888
#
8989
html_theme = "pydata_sphinx_theme"
90+
html_logo = "_static/logo.png"
9091

9192
# Add any paths that contain custom static files (such as style sheets) here,
9293
# relative to this directory. They are copied after the builtin static files,

docs/guide/index.rst

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/index.rst

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
napari-matplotlib
22
=================
3-
``napari-matplotlib`` is a `Napari <https://napari.org>`_ plugin for generating
3+
A `napari <https://napari.org>`_ plugin for generating
44
`Matplotlib <https://matplotlib.org/>`_ plots from one or more ``napari`` Layers.
55

6-
Design
7-
------
8-
``napari-matplotlib`` contains a number of different ``napari`` Widgets. Each
9-
widget is designed to map one or more ``napari`` Layers on to a ``matplotlib`` plot.
6+
This plugin provides a number of different ``napari`` Widgets. Each
7+
widget is designed to map one or more ``napari`` Layers on to a ``Matplotlib`` plot.
108
As an example, the `~.HistogramWidget` is used to
119
map one or more Image layers on to a 1D histogram plot.
1210

13-
.. toctree::
14-
:maxdepth: 1
15-
16-
guide/index
11+
.. image:: _static/hist.png
12+
:alt: Screenshot of the napari viewer showing the napari-matplotlib histogram widget on the right hand side of the screen.
1713

1814
.. toctree::
1915
:maxdepth: 1
20-
:caption: Reference
16+
:hidden:
2117

18+
user_guide
19+
auto_examples/index
20+
third_party
2221
api
2322
changelog

docs/guide/third_party.rst renamed to docs/third_party.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
Third-party plugins
22
===================
3-
This page explains how ``napari-matplotlib`` can be used within third party plugins.
4-
5-
``napari-matplotlib`` provides a ready-to-go widget with a Matplotlib toolbar and figure to third party plugin developers
3+
``napari-matplotlib`` provides a ready-to-go widget with a Matplotlib toolbar and figure to third party plugin developers.
64
This widget is customised to match the theme of the main napari window.
75

86
The widget can be found at `napari_matplotlib.base.NapariMPLWidget`.

docs/guide/user_guide.rst renamed to docs/user_guide.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,14 @@ To use these:
3636
1. Open the desired widget using the ``Plugins > napari-matplotlib`` menu in napari.
3737
2. Select a single layer that has a features table using the napari layers list in the bottom left-hand side of the window.
3838
3. Use the drop down menu(s) under the Matplotlib figure to select the feature(s) to plot.
39+
40+
Customising plots
41+
-----------------
42+
`Matplotlib style sheets <https://matplotlib.org/stable/tutorials/introductory/customizing.html#defining-your-own-style>`__ can be used to customise
43+
the plots generated by ``napari-matplotlib``.
44+
To use a custom style sheet:
45+
46+
1. Save it as ``napari-matplotlib.mplstyle``
47+
2. Put it in the Matplotlib configuration directory.
48+
The location of this directory varies on different computers,
49+
and can be found by calling :func:`matplotlib.get_configdir()`.

examples/README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Examples
2-
========
1+
Gallery
2+
=======

examples/features_scatter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
import napari
77
import numpy as np
8+
import numpy.typing as npt
89
from skimage.measure import regionprops_table
910

1011
# make a test label image
11-
label_image = np.zeros((100, 100), dtype=np.uint16)
12+
label_image: npt.NDArray[np.uint16] = np.zeros((100, 100), dtype=np.uint16)
1213

1314
label_image[10:20, 10:20] = 1
1415
label_image[50:70, 50:70] = 2

setup.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ classifiers =
2020
Topic :: Software Development :: Testing
2121
project_urls =
2222
Bug Tracker = https://github.com/matplotlib/napari-matplotlib/issues
23-
Documentation = https://github.com/matplotlib/napari-matplotlib#README.md
23+
Documentation = https://napari-matplotlib.github.io
2424
Source Code = https://github.com/matplotlib/napari-matplotlib
2525
User Support = https://github.com/matplotlib/napari-matplotlib/issues
2626

@@ -47,15 +47,15 @@ napari.manifest =
4747

4848
[options.extras_require]
4949
docs =
50-
napari[all]
50+
napari[all]==0.4.17
5151
numpydoc
5252
pydata-sphinx-theme
5353
qtgallery
5454
sphinx
5555
sphinx-automodapi
5656
sphinx-gallery
5757
testing =
58-
napari[pyqt6-experimental]
58+
napari[pyqt6_experimental]>=0.4.18
5959
pooch
6060
pyqt6
6161
pytest

src/napari_matplotlib/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pathlib import Path
33
from typing import List, Optional, Tuple
44

5+
import matplotlib
56
import matplotlib.style as mplstyle
67
import napari
78
from matplotlib.backends.backend_qtagg import (
@@ -16,6 +17,10 @@
1617

1718
__all__ = ["BaseNapariMPLWidget", "NapariMPLWidget", "SingleAxesWidget"]
1819

20+
_CUSTOM_STYLE_PATH = (
21+
Path(matplotlib.get_configdir()) / "napari-matplotlib.mplstyle"
22+
)
23+
1924

2025
class BaseNapariMPLWidget(QWidget):
2126
"""
@@ -46,7 +51,6 @@ def __init__(
4651
with mplstyle.context(self.mpl_style_sheet_path):
4752
self.canvas = FigureCanvas()
4853

49-
self.canvas.figure.patch.set_facecolor("none")
5054
self.canvas.figure.set_layout_engine("constrained")
5155
self.toolbar = NapariNavigationToolbar(
5256
self.canvas, parent=self
@@ -73,6 +77,8 @@ def mpl_style_sheet_path(self) -> Path:
7377
"""
7478
if self._mpl_style_sheet_path is not None:
7579
return self._mpl_style_sheet_path
80+
elif (_CUSTOM_STYLE_PATH).exists():
81+
return _CUSTOM_STYLE_PATH
7682
elif self._napari_theme_has_light_bg():
7783
return Path(__file__).parent / "styles" / "light.mplstyle"
7884
else:

src/napari_matplotlib/histogram.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,19 @@ def draw(self) -> None:
3535
Clear the axes and histogram the currently selected layer/slice.
3636
"""
3737
layer = self.layers[0]
38-
bins = np.linspace(np.min(layer.data), np.max(layer.data), 100)
3938

4039
if layer.data.ndim - layer.rgb == 3:
4140
# 3D data, can be single channel or RGB
4241
data = layer.data[self.current_z]
4342
self.axes.set_title(f"z={self.current_z}")
4443
else:
4544
data = layer.data
45+
# Read data into memory if it's a dask array
46+
data = np.asarray(data)
47+
48+
# Important to calculate bins after slicing 3D data, to avoid reading
49+
# whole cube into memory.
50+
bins = np.linspace(np.min(data), np.max(data), 100)
4651

4752
if layer.rgb:
4853
# Histogram RGB channels independently

0 commit comments

Comments
 (0)