Skip to content
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
4 changes: 1 addition & 3 deletions src/plopp/backends/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from ...graphics import BaseFig
from .canvas import Canvas
from .utils import fig_to_bytes
from .utils import fig_to_bytes, is_interactive_backend

try:
from ipywidgets import VBox
Expand Down Expand Up @@ -189,8 +189,6 @@ def to_widget(self):


def Figure(*args, **kwargs):
from .utils import is_interactive_backend

if is_interactive_backend():
return InteractiveFigure(*args, **kwargs)
else:
Expand Down
3 changes: 1 addition & 2 deletions src/plopp/backends/plotly/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from typing import Literal

import plotly.graph_objects as go
import scipp as sc

from ...core.utils import maybe_variable_to_number
Expand Down Expand Up @@ -62,8 +63,6 @@ def __init__(
ymax = parse_mutually_exclusive(vmax=user_vmax, ymax=ymax)
logy = parse_mutually_exclusive(norm=norm, logy=logy)

import plotly.graph_objects as go

self.fig = go.FigureWidget(
layout={
'modebar_remove': [
Expand Down
6 changes: 2 additions & 4 deletions src/plopp/backends/pythreejs/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

import ipywidgets as ipw
import numpy as np
import pythreejs as p3
import scipp as sc

from ...graphics import Camera
from ...graphics.bbox import BoundingBox
from .outline import Outline


class Canvas:
Expand Down Expand Up @@ -41,8 +43,6 @@ def __init__(
perspective: bool = True,
**ignored,
):
import pythreejs as p3

self.dims = {}
self.units = {}
self.xscale = 'linear'
Expand Down Expand Up @@ -190,8 +190,6 @@ def draw(self) -> None:
"""
Create an outline box with ticklabels, given a range in the XYZ directions.
"""
from .outline import Outline

# If `None` is found in the limits, it means we are waiting first for a call
# to autoscale on the parent view.
if self.empty or (None in self.bbox.asdict().values()):
Expand Down
2 changes: 1 addition & 1 deletion src/plopp/backends/pythreejs/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os

from ipywidgets import HBox, VBox
from ipywidgets.embed import dependency_state, embed_minimal_html

from ...graphics import BaseFig
from ...widgets import HBar, VBar, make_toolbar_canvas3d
Expand Down Expand Up @@ -48,7 +49,6 @@ def save(self, filename):
ext = os.path.splitext(filename)[1]
if ext.lower() != '.html':
raise ValueError('File extension must be .html for saving 3d figures.')
from ipywidgets.embed import dependency_state, embed_minimal_html

out = HBox([self.view.canvas.to_widget(), self.right_bar])
# Garbage collection for embedded html output:
Expand Down
3 changes: 1 addition & 2 deletions src/plopp/backends/pythreejs/mesh3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Literal

import numpy as np
import pythreejs as p3
import scipp as sc
from matplotlib.colors import to_rgb

Expand Down Expand Up @@ -59,8 +60,6 @@ def __init__(
artist_number: int = 0,
**ignored,
):
import pythreejs as p3

self.uid = uid if uid is not None else uuid.uuid4().hex
self._data = data
self._canvas = canvas
Expand Down
3 changes: 1 addition & 2 deletions src/plopp/backends/pythreejs/scatter3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Literal

import numpy as np
import pythreejs as p3
import scipp as sc
from matplotlib.colors import to_rgb

Expand Down Expand Up @@ -66,8 +67,6 @@ def __init__(
pixel_size: sc.Variable | float | None = None,
mask_color: str | None = None,
):
import pythreejs as p3

check_ndim(data, ndim=1, origin='Scatter3d')
self.uid = uid if uid is not None else uuid.uuid4().hex
self._canvas = canvas
Expand Down
3 changes: 1 addition & 2 deletions src/plopp/data/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
from functools import lru_cache

import numpy as np
import pooch
import scipp as sc

_version = '1'


@lru_cache(maxsize=1)
def _make_pooch():
import pooch

return pooch.create(
path=pooch.os_cache('plopp'),
env='PLOPP_DATA_DIR',
Expand Down
3 changes: 1 addition & 2 deletions src/plopp/plotting/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ..core.typing import Plottable
from ..core.utils import coord_as_bin_edges
from ..graphics import imagefigure, linefigure
from ..widgets import Box, PointsTool, PolygonTool, RectangleTool
from .common import preprocess, require_interactive_figure


Expand Down Expand Up @@ -300,8 +301,6 @@ def inspector(
ylabel=ylabel,
**kwargs,
)
from ..widgets import Box, PointsTool, PolygonTool, RectangleTool

if mode == 'point':
tool = PointsTool(
figure=f2d,
Expand Down
4 changes: 1 addition & 3 deletions src/plopp/plotting/mesh3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from ..core import Node
from ..core.typing import FigureLike, Plottable
from ..graphics import Camera
from ..graphics import Camera, mesh3dfigure
from .common import _maybe_to_variable


Expand Down Expand Up @@ -110,8 +110,6 @@ def mesh3d(
**kwargs:
All other kwargs are forwarded the underlying plotting library.
"""
from ..graphics import mesh3dfigure

input_node = Node(
_preprocess_mesh,
vertices=vertices,
Expand Down
3 changes: 1 addition & 2 deletions src/plopp/plotting/scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import scipp as sc

from ..core.typing import FigureLike, PlottableMulti
from ..graphics import scatterfigure
from .common import check_not_binned, check_size, from_compatible_lib, input_to_nodes


Expand Down Expand Up @@ -158,8 +159,6 @@ def scatter(
**kwargs:
All other kwargs are forwarded the underlying plotting library.
"""
from ..graphics import scatterfigure

nodes = input_to_nodes(
obj,
processor=partial(
Expand Down
6 changes: 2 additions & 4 deletions src/plopp/plotting/scatter3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import scipp as sc

from ..core.typing import FigureLike, PlottableMulti
from ..graphics import Camera
from ..graphics import Camera, scatter3dfigure
from ..widgets import ClippingManager, ToggleTool
from .common import check_not_binned, from_compatible_lib, input_to_nodes


Expand Down Expand Up @@ -132,9 +133,6 @@ def scatter3d(
:
A three-dimensional interactive scatter plot.
"""
from ..graphics import scatter3dfigure
from ..widgets import ClippingManager, ToggleTool

if 'ax' in kwargs:
raise ValueError(
'Keyword "ax" detected. Embedding 3D scatter plots inside Matplotlib axes '
Expand Down
8 changes: 1 addition & 7 deletions src/plopp/plotting/slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ..core import Node, widget_node
from ..core.typing import FigureLike, PlottableMulti
from ..graphics import imagefigure, linefigure
from ..widgets import CombinedSliceWidget, RangeSliceWidget, SliceWidget, slice_dims
from .common import (
categorize_args,
input_to_nodes,
Expand Down Expand Up @@ -132,13 +133,6 @@ def __init__(
f"were not found in the input's dimensions {dims}."
)

from ..widgets import (
CombinedSliceWidget,
RangeSliceWidget,
SliceWidget,
slice_dims,
)

other_dims = [dim for dim in dims if dim not in keep]

match mode:
Expand Down
3 changes: 1 addition & 2 deletions src/plopp/plotting/superplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import scipp as sc

from ..core.typing import FigureLike, Plottable
from ..widgets import LineSaveTool
from .slicer import Slicer


Expand Down Expand Up @@ -108,8 +109,6 @@ def superplot(
A :class:`widgets.Box` which will contain a :class:`graphics.FigLine`, slider
widgets and a tool to save/delete lines.
"""
from ..widgets import LineSaveTool

slicer = Slicer(
obj,
keep=keep,
Expand Down
3 changes: 1 addition & 2 deletions src/plopp/widgets/clip3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import ipywidgets as ipw
import numpy as np
import pythreejs as p3
import scipp as sc

from ..core import Node
Expand Down Expand Up @@ -80,8 +81,6 @@ def __init__(
width = (self._limits[w_axis][1] - self._limits[w_axis][0]).value
height = (self._limits[h_axis][1] - self._limits[h_axis][0]).value

import pythreejs as p3

self.outlines = [
p3.LineSegments(
geometry=p3.EdgesGeometry(
Expand Down
37 changes: 4 additions & 33 deletions src/plopp/widgets/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from functools import partial
from typing import Any

import mpltoolbox as tbx
import scipp as sc

from ..core import Node, node
Expand Down Expand Up @@ -154,19 +155,9 @@ def _get_points_info(artist, figure):
}


def _make_points(**kwargs):
"""
Intermediate function needed for giving to `partial` to avoid making mpltoolbox a
hard dependency.
"""
from mpltoolbox import Points

return Points(**kwargs)


PointsTool = partial(
DrawingTool,
tool=partial(_make_points, mec='w'),
tool=partial(tbx.Points, mec='w'),
get_artist_info=_get_points_info,
icon='crosshairs',
)
Expand Down Expand Up @@ -218,19 +209,9 @@ def _get_rect_info(artist, figure):
}


def _make_rectangles(**kwargs):
"""
Intermediate function needed for giving to `partial` to avoid making mpltoolbox a
hard dependency.
"""
from mpltoolbox import Rectangles

return Rectangles(**kwargs)


RectangleTool = partial(
DrawingTool,
tool=_make_rectangles,
tool=tbx.Rectangles,
get_artist_info=_get_rect_info,
icon='object-ungroup' if RUNNING_IN_VSCODE else 'vector-square',
)
Expand Down Expand Up @@ -261,19 +242,9 @@ def _get_polygon_info(artist, figure):
}


def _make_polygons(**kwargs):
"""
Intermediate function needed for giving to `partial` to avoid making mpltoolbox a
hard dependency.
"""
from mpltoolbox import Polygons

return Polygons(**kwargs)


PolygonTool = partial(
DrawingTool,
tool=partial(_make_polygons, mec='w'),
tool=partial(tbx.Polygons, mec='w'),
get_artist_info=_get_polygon_info,
icon='object-ungroup' if RUNNING_IN_VSCODE else 'draw-polygon',
)
Expand Down
3 changes: 1 addition & 2 deletions src/plopp/widgets/linesave.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ..core import Node, View
from ..core.utils import coord_element_to_string
from .box import VBar
from .tools import ColorTool


class LineSaveTool(VBar):
Expand Down Expand Up @@ -41,8 +42,6 @@ def _update_container(self):
self.container.children = [line['tool'] for line in self._lines.values()]

def save_line(self, change: dict[str, Any] | None = None):
from ..widgets import ColorTool

data = self._data_node.request_data()
node = Node(data)
node.pretty_name = f'Save node {len(self._lines)}'
Expand Down
Loading