Skip to content

Commit 8c6b663

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 1054298 commit 8c6b663

File tree

3 files changed

+53
-72
lines changed

3 files changed

+53
-72
lines changed

src/spatialdata_plot/pl/basic.py

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,49 @@
11
from __future__ import annotations
2+
23
from collections import OrderedDict
3-
from typing import Callable, Optional, Union, Any, Sequence
4+
from typing import Any, Optional, Union
5+
from collections.abc import Sequence
46

57
import geopandas as gpd
6-
import matplotlib
7-
import matplotlib.pyplot as plt
88
import numpy as np
9-
import pandas as pd
109
import scanpy as sc
1110
import spatialdata as sd
12-
import xarray as xr
1311
from anndata import AnnData
1412
from dask.dataframe.core import DataFrame as DaskDataFrame
1513
from geopandas import GeoDataFrame
14+
from matplotlib.axes import Axes
15+
from matplotlib.colors import Colormap, Normalize
16+
from matplotlib.figure import Figure
1617
from multiscale_spatial_image.multiscale_spatial_image import MultiscaleSpatialImage
1718
from pandas.api.types import is_categorical_dtype
1819
from spatial_image import SpatialImage
1920
from spatialdata import transform
20-
from spatialdata.models import Image2DModel, TableModel
21+
from spatialdata.models import Image2DModel
2122
from spatialdata.transformations import get_transformation
22-
from matplotlib.colors import Colormap
23-
from matplotlib.figure import Figure
24-
from matplotlib.gridspec import GridSpec
25-
from matplotlib import colors, patheffects, rcParams
26-
from matplotlib import pyplot as plt
27-
from matplotlib.axes import Axes
23+
2824
from spatialdata_plot._accessor import register_spatial_data_accessor
29-
from spatialdata_plot.pp.utils import (
30-
_get_instance_key,
31-
_get_region_key,
32-
_verify_plotting_tree,
33-
)
3425
from spatialdata_plot.pl.render import (
26+
ImageRenderParams,
27+
LabelsRenderParams,
28+
ShapesRenderParams,
3529
_render_images,
3630
_render_labels,
3731
_render_points,
3832
_render_shapes,
39-
LabelsRenderParams,
40-
ImageRenderParams,
41-
ShapesRenderParams,
4233
)
4334
from spatialdata_plot.pl.utils import (
44-
_get_hex_colors_for_continous_values,
45-
_get_random_hex_colors,
46-
_get_subplots,
47-
_maybe_set_colors,
48-
Palette_t,
49-
CmapParams,
5035
LegendParams,
36+
Palette_t,
37+
_FontSize,
38+
_FontWeight,
39+
_maybe_set_colors,
5140
_prepare_cmap_norm,
5241
_prepare_params_plot,
5342
_set_outline,
54-
_FontSize,
55-
_FontWeight,
5643
)
57-
from matplotlib.colors import ListedColormap, Normalize, to_rgb
58-
from dataclasses import dataclass
44+
from spatialdata_plot.pp.utils import (
45+
_verify_plotting_tree,
46+
)
5947

6048

6149
@register_spatial_data_accessor("pl")
@@ -575,7 +563,7 @@ def show(
575563

576564
# go through tree
577565
for cmd, params in render_cmds.items():
578-
keys = list(sdata.images.keys())
566+
list(sdata.images.keys())
579567

580568
if cmd == "render_images":
581569
_render_images(

src/spatialdata_plot/pl/render.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,38 @@
22

33
from collections.abc import Iterable, Sequence
44
from copy import copy
5+
from dataclasses import dataclass
56
from functools import partial
6-
from typing import Callable, Optional, Union, Any
7-
from matplotlib.colors import Colormap
7+
from typing import Any, Optional, Union
8+
89
import matplotlib
9-
from spatialdata.models import TableModel
10-
import matplotlib.patches as mpatches
11-
import matplotlib.pyplot as plt
1210
import numpy as np
1311
import spatialdata as sd
14-
from scanpy._settings import settings as sc_settings
15-
import xarray as xr
12+
from geopandas import GeoDataFrame
1613
from matplotlib import colors
17-
from matplotlib.cm import get_cmap
18-
from matplotlib.colors import ListedColormap, Normalize, to_rgb, TwoSlopeNorm, ColorConverter
19-
from matplotlib.collections import Collection, PatchCollection
14+
from matplotlib.collections import PatchCollection
15+
from matplotlib.colors import (
16+
ColorConverter,
17+
ListedColormap,
18+
Normalize,
19+
)
2020
from matplotlib.patches import Circle, Polygon
2121
from pandas.api.types import is_categorical_dtype
22-
from geopandas import GeoDataFrame
23-
from sklearn.decomposition import PCA
24-
from dataclasses import dataclass
22+
from scanpy._settings import settings as sc_settings
23+
from spatialdata.models import TableModel
24+
2525
from spatialdata_plot.pl.utils import (
2626
CmapParams,
27-
LegendParams,
2827
FigParams,
29-
ScalebarParams,
28+
LegendParams,
3029
OutlineParams,
30+
ScalebarParams,
31+
_decorate_axs,
32+
_get_palette,
3133
_map_color_seg,
3234
_normalize,
3335
_set_color_source_vec,
34-
_get_palette,
35-
_decorate_axs,
3636
)
37-
from spatialdata_plot.pp.utils import _get_linear_colormap, _get_region_key
3837

3938
Palette_t = Optional[Union[str, ListedColormap]]
4039
_Normalize = Union[Normalize, Sequence[Normalize]]
@@ -300,7 +299,6 @@ def _render_labels(
300299
# ax: matplotlib.axes.SubplotBase,
301300
# extent: dict[str, list[int]],
302301
) -> None:
303-
304302
# get instance and region keys
305303
instance_key = str(sdata.table.uns[TableModel.ATTRS_KEY][TableModel.INSTANCE_KEY])
306304
region_key = str(sdata.table.uns[TableModel.ATTRS_KEY][TableModel.REGION_KEY_KEY])

src/spatialdata_plot/pl/utils.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
11
from __future__ import annotations
22

33
from collections.abc import Iterable, Mapping, Sequence
4+
from copy import copy
5+
from dataclasses import dataclass
46
from functools import partial
5-
from typing import Any, NamedTuple, Optional, Union, Literal, Type
67
from types import MappingProxyType
7-
from copy import copy
8+
from typing import Any, Literal, Optional, Type, Union
9+
810
import matplotlib.pyplot as plt
911
import numpy as np
1012
import pandas as pd
1113
import xarray as xr
1214
from anndata import AnnData
1315
from cycler import Cycler, cycler
14-
from matplotlib import colors
15-
from matplotlib.colors import Colormap, ListedColormap, Normalize, to_rgba, TwoSlopeNorm
16+
from matplotlib import colors, patheffects
17+
from matplotlib import pyplot as plt
18+
from matplotlib import rcParams
19+
from matplotlib.axes import Axes
1620
from matplotlib.cm import get_cmap
21+
from matplotlib.collections import PatchCollection
22+
from matplotlib.colors import Colormap, ListedColormap, Normalize, TwoSlopeNorm, to_rgba
23+
from matplotlib.figure import Figure
24+
from matplotlib.gridspec import GridSpec
25+
from matplotlib_scalebar.scalebar import ScaleBar
1726
from numpy.random import default_rng
1827
from pandas.api.types import CategoricalDtype, is_categorical_dtype
28+
from scanpy.plotting._tools.scatterplots import _add_categorical_legend
29+
from scanpy.plotting.palettes import default_20, default_28, default_102
1930
from skimage.color import label2rgb
2031
from skimage.morphology import erosion, square
2132
from skimage.segmentation import find_boundaries
2233
from skimage.util import map_array
23-
from spatialdata._types import ArrayLike
2434
from spatialdata._logging import logger as logging
25-
from matplotlib import rcParams
26-
from scanpy.plotting.palettes import default_20, default_28, default_102
27-
from dataclasses import dataclass
28-
from matplotlib_scalebar.scalebar import ScaleBar
29-
from matplotlib.figure import Figure
30-
from matplotlib.gridspec import GridSpec
31-
from matplotlib import colors, patheffects, rcParams
32-
from matplotlib import pyplot as plt
33-
from matplotlib.axes import Axes
34-
from matplotlib.collections import Collection, PatchCollection
35-
from scanpy._settings import settings as sc_settings
36-
from scanpy.plotting._tools.scatterplots import _add_categorical_legend
35+
from spatialdata._types import ArrayLike
3736

3837
Palette_t = Optional[Union[str, ListedColormap]]
3938
_Normalize = Union[Normalize, Sequence[Normalize]]
@@ -89,7 +88,6 @@ def _prepare_params_plot(
8988
scalebar_dx: float | Sequence[float] | None = None,
9089
scalebar_units: str | Sequence[str] | None = None,
9190
) -> tuple[FigParams, ScalebarParams]:
92-
9391
# len(list(itertools.product(*iter_panels)))
9492

9593
# handle axes and size
@@ -193,7 +191,6 @@ def _prepare_cmap_norm(
193191
vmax: float | None = None,
194192
vcenter: float | None = None,
195193
) -> dataclass:
196-
197194
cmap = copy(get_cmap(cmap))
198195
cmap.set_bad("lightgray" if na_color is None else na_color)
199196

@@ -460,7 +457,6 @@ def _map_color_seg(
460457
seg_boundaries: bool = False,
461458
na_color: str | tuple[float, ...] = (0, 0, 0, 0),
462459
) -> ArrayLike:
463-
464460
cell_id = np.array(cell_id)
465461

466462
if is_categorical_dtype(color_vector):
@@ -601,7 +597,6 @@ def _decorate_axs(
601597
scalebar_units: Sequence[str] | None = None,
602598
scalebar_kwargs: Mapping[str, Any] = MappingProxyType({}),
603599
) -> Axes:
604-
605600
ax.set_yticks([])
606601
ax.set_xticks([])
607602
# ax.set_xlabel(fig_params.ax_labels[0])
@@ -654,7 +649,7 @@ def _decorate_axs(
654649

655650
def _get_list(
656651
var: Any,
657-
_type: Type[Any] | tuple[Type[Any], ...],
652+
_type: type[Any] | tuple[type[Any], ...],
658653
ref_len: int | None = None,
659654
name: str | None = None,
660655
) -> list[Any]:

0 commit comments

Comments
 (0)