diff --git a/docs/about/reference.rst b/docs/about/reference.rst index 57bac433..3cbd045c 100644 --- a/docs/about/reference.rst +++ b/docs/about/reference.rst @@ -37,12 +37,12 @@ Graphics graphics.Camera graphics.ColorMapper - graphics.FigImage - graphics.FigLine - graphics.FigScatter3d graphics.figure1d graphics.figure2d graphics.figure3d + graphics.ImageView + graphics.LineView + graphics.Scatter3dView graphics.tiled Widgets and tools diff --git a/src/plopp/__init__.py b/src/plopp/__init__.py index 3be01ace..0ee00816 100644 --- a/src/plopp/__init__.py +++ b/src/plopp/__init__.py @@ -16,8 +16,8 @@ from . import data from .core import Node, View, input_node, node, show_graph, widget_node -from .functions import inspector, plot, scatter3d, slicer, superplot from .graphics import Camera, figure1d, figure2d, figure3d, tiled +from .plotting import inspector, plot, scatter3d, slicer, superplot def patch_scipp(): diff --git a/src/plopp/backends/matplotlib/figure.py b/src/plopp/backends/matplotlib/figure.py index 6ed8e9c0..7cddec8b 100644 --- a/src/plopp/backends/matplotlib/figure.py +++ b/src/plopp/backends/matplotlib/figure.py @@ -1,85 +1,39 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) 2023 Scipp contributors (https://github.com/scipp) +from ...graphics import BaseFig -class Figure: + +class Figure(BaseFig): """ Mixin class for Matplotlib figures """ - def __init_figure__(self, FigConstructor, *args, **kwargs): - self._fig = FigConstructor(*args, **kwargs) + def __init_figure__(self, View, *args, **kwargs): + self._view = View(*args, **kwargs) self._args = args self._kwargs = kwargs - self._fig_constructor = FigConstructor @property def fig(self): """ Get the underlying Matplotlib figure. """ - return self._fig.canvas.fig + return self._view.canvas.fig @property def ax(self): """ Get the underlying Matplotlib axes. """ - return self._fig.canvas.ax + return self._view.canvas.ax @property def cax(self): """ Get the underlying Matplotlib colorbar axes. """ - return self._fig.canvas.cax - - @property - def canvas(self): - return self._fig.canvas - - @property - def artists(self): - return self._fig.artists - - @property - def graph_nodes(self): - return self._fig.graph_nodes - - @property - def id(self): - return self._fig.id - - def crop(self, **limits): - """ - Set the axes limits according to the crop parameters. - - Parameters - ---------- - **limits: - Min and max limits for each dimension to be cropped. - """ - return self._fig.crop(**limits) - - def save(self, filename, **kwargs): - """ - Save the figure to file. - The default directory for writing the file is the same as the - directory where the script or notebook is running. - - Parameters - ---------- - filename: - Name of the output file. Possible file extensions are ``.jpg``, ``.png``, - ``.svg``, and ``.pdf``. - """ - return self._fig.canvas.save(filename, **kwargs) - - def update(self, *args, **kwargs): - return self._fig.update(*args, **kwargs) - - def notify_view(self, *args, **kwargs): - return self._fig.notify_view(*args, **kwargs) + return self._view.canvas.cax def __add__(self, other): from .tiled import hstack diff --git a/src/plopp/backends/matplotlib/interactive.py b/src/plopp/backends/matplotlib/interactive.py index d6b1dc05..0745fd96 100644 --- a/src/plopp/backends/matplotlib/interactive.py +++ b/src/plopp/backends/matplotlib/interactive.py @@ -12,10 +12,11 @@ class InteractiveFig(Figure, VBox): Create an interactive Matplotlib figure. """ - def __init__(self, FigConstructor, *args, **kwargs): - self.__init_figure__(FigConstructor, *args, **kwargs) + def __init__(self, View, *args, **kwargs): + self.__init_figure__(View, *args, **kwargs) self.toolbar = make_toolbar_canvas2d( - canvas=self._fig.canvas, colormapper=getattr(self._fig, 'colormapper', None) + canvas=self._view.canvas, + colormapper=getattr(self._view, 'colormapper', None), ) self.left_bar = VBar([self.toolbar]) self.right_bar = VBar() @@ -25,7 +26,7 @@ def __init__(self, FigConstructor, *args, **kwargs): super().__init__( [ self.top_bar, - HBox([self.left_bar, self._fig.canvas.to_widget(), self.right_bar]), + HBox([self.left_bar, self._view.canvas.to_widget(), self.right_bar]), self.bottom_bar, ] ) diff --git a/src/plopp/backends/matplotlib/static.py b/src/plopp/backends/matplotlib/static.py index 60338f1c..d01a5797 100644 --- a/src/plopp/backends/matplotlib/static.py +++ b/src/plopp/backends/matplotlib/static.py @@ -33,8 +33,8 @@ class StaticFig(Figure): canvas. """ - def __init__(self, FigConstructor, *args, **kwargs): - self.__init_figure__(FigConstructor, *args, **kwargs) + def __init__(self, View, *args, **kwargs): + self.__init_figure__(View, *args, **kwargs) def _repr_mimebundle_(self, include=None, exclude=None) -> dict: """ @@ -42,16 +42,16 @@ def _repr_mimebundle_(self, include=None, exclude=None) -> dict: """ str_repr = str(self.fig) out = {'text/plain': str_repr[:-1] + f', {len(self.artists)} artists)'} - if self._fig._repr_format is not None: - repr_maker = get_repr_maker(form=self._fig._repr_format) + if self._view._repr_format is not None: + repr_maker = get_repr_maker(form=self._view._repr_format) else: - npoints = sum(len(line.get_xdata()) for line in self._fig.canvas.ax.lines) + npoints = sum(len(line.get_xdata()) for line in self._view.canvas.ax.lines) repr_maker = get_repr_maker(npoints=npoints) - out.update(repr_maker(self._fig.canvas.fig)) + out.update(repr_maker(self._view.canvas.fig)) return out def to_widget(self): """ Convert the Matplotlib figure to an image widget. """ - return self._fig.canvas.to_image() + return self._view.canvas.to_image() diff --git a/src/plopp/backends/matplotlib/utils.py b/src/plopp/backends/matplotlib/utils.py index 6656b725..3e9c9e9d 100644 --- a/src/plopp/backends/matplotlib/utils.py +++ b/src/plopp/backends/matplotlib/utils.py @@ -98,7 +98,7 @@ def is_sphinx_build() -> bool: def copy_figure(fig: FigureLike, **kwargs) -> FigureLike: out = fig.__class__( - fig._fig_constructor, + fig._view.__class__, *fig._args, **{**fig._kwargs, **kwargs}, ) diff --git a/src/plopp/backends/plotly/figure.py b/src/plopp/backends/plotly/figure.py index b12e8c35..00321f16 100644 --- a/src/plopp/backends/plotly/figure.py +++ b/src/plopp/backends/plotly/figure.py @@ -3,17 +3,18 @@ from ipywidgets import HBox, VBox +from ...graphics import BaseFig from ...widgets import HBar, VBar, make_toolbar_canvas2d -class Figure(VBox): +class Figure(BaseFig, VBox): """ Create an interactive figure to represent one-dimensional data. """ - def __init__(self, FigConstructor, *args, **kwargs): - self._fig = FigConstructor(*args, **kwargs) - self.toolbar = make_toolbar_canvas2d(canvas=self._fig.canvas) + def __init__(self, View, *args, **kwargs): + self._view = View(*args, **kwargs) + self.toolbar = make_toolbar_canvas2d(canvas=self._view.canvas) self.left_bar = VBar([self.toolbar]) self.right_bar = VBar() self.bottom_bar = HBar() @@ -22,54 +23,7 @@ def __init__(self, FigConstructor, *args, **kwargs): super().__init__( [ self.top_bar, - HBox([self.left_bar, self._fig.canvas.to_widget(), self.right_bar]), + HBox([self.left_bar, self._view.canvas.to_widget(), self.right_bar]), self.bottom_bar, ] ) - - @property - def canvas(self): - return self._fig.canvas - - @property - def artists(self): - return self._fig.artists - - @property - def graph_nodes(self): - return self._fig.graph_nodes - - @property - def id(self): - return self._fig.id - - def crop(self, **limits): - """ - Set the axes limits according to the crop parameters. - - Parameters - ---------- - **limits: - Min and max limits for each dimension to be cropped. - """ - return self._fig.crop(**limits) - - def save(self, filename, **kwargs): - """ - Save the figure to file. - The default directory for writing the file is the same as the - directory where the script or notebook is running. - - Parameters - ---------- - filename: - Name of the output file. Possible file extensions are ``.jpg``, ``.png``, - ``.svg``, ``.pdf``, and ``html``. - """ - return self._fig.canvas.save(filename, **kwargs) - - def update(self, *args, **kwargs): - return self._fig.update(*args, **kwargs) - - def notify_view(self, *args, **kwargs): - return self._fig.notify_view(*args, **kwargs) diff --git a/src/plopp/core/view.py b/src/plopp/core/view.py index ed4e64d4..76c74ff0 100644 --- a/src/plopp/core/view.py +++ b/src/plopp/core/view.py @@ -3,6 +3,9 @@ import uuid from abc import abstractmethod +from typing import Any, Dict + +import scipp as sc class View: @@ -23,19 +26,42 @@ def __init__(self, *nodes): self.graph_nodes = {} for node in nodes: node.add_view(self) + self.artists = {} + + @property + def id(self): + """ + The unique id of the view. + """ + return self._id + + def notify_view(self, message: Dict[str, Any]): + """ + When a notification is received, request data from the corresponding parent node + and update the relevant artist. + + Parameters + ---------- + *message: + The notification message containing the node id it originated from. + """ + node_id = message["node_id"] + new_values = self.graph_nodes[node_id].request_data() + self.update(new_values=new_values, key=node_id) @abstractmethod - def notify_view(self, _): + def update(self, new_values: sc.DataArray, key: str, draw: bool): """ - The function that will be called when a parent node is told to notify its - children and its views. + Update function which is called when a notification is received. This has to be overridden by any child class. """ - return + ... - @property - def id(self): + def render(self): """ - The unique id of the view. + At the end of figure creation, this function is called to request data from + all parent nodes and draw the figure. """ - return self._id + for node in self.graph_nodes.values(): + new_values = node.request_data() + self.update(new_values=new_values, key=node.id) diff --git a/src/plopp/graphics/__init__.py b/src/plopp/graphics/__init__.py index d3653cc2..39ac1ad8 100644 --- a/src/plopp/graphics/__init__.py +++ b/src/plopp/graphics/__init__.py @@ -3,10 +3,11 @@ # flake8: noqa E402, F401 +from .basefig import BaseFig from .camera import Camera from .colormapper import ColorMapper -from .figimage import FigImage -from .figline import FigLine -from .figscatter3d import FigScatter3d from .figure import figure1d, figure2d, figure3d +from .imageview import ImageView +from .lineview import LineView +from .scatter3dview import Scatter3dView from .tiled import tiled diff --git a/src/plopp/graphics/basefig.py b/src/plopp/graphics/basefig.py index 28aa0410..e0b2cb8d 100644 --- a/src/plopp/graphics/basefig.py +++ b/src/plopp/graphics/basefig.py @@ -1,55 +1,60 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) 2023 Scipp contributors (https://github.com/scipp) -from abc import abstractmethod -from typing import Any, Dict - -import scipp as sc from ..core import View -class BaseFig(View): +class BaseFig: """ - A :class:`View` for figures. - - Parameters - ---------- - *nodes: - The nodes that are attached to the view. + A Mixin class which is the base for all figures. """ - def __init__(self, *nodes): - super().__init__(*nodes) - self.artists = {} + _view: View + + @property + def canvas(self): + return self._view.canvas + + @property + def artists(self): + return self._view.artists + + @property + def graph_nodes(self): + return self._view.graph_nodes + + @property + def id(self): + return self._view.id - def notify_view(self, message: Dict[str, Any]): + def crop(self, **limits): """ - When a notification is received, request data from the corresponding parent node - and update the relevant artist. + Set the axes limits according to the crop parameters. Parameters ---------- - *message: - The notification message containing the node id it originated from. + **limits: + Min and max limits for each dimension to be cropped. """ - node_id = message["node_id"] - new_values = self.graph_nodes[node_id].request_data() - self.update(new_values=new_values, key=node_id) + return self._view.crop(**limits) - @abstractmethod - def update(self, new_values: sc.DataArray, key: str, draw: bool): + def save(self, filename, **kwargs): """ - Update function which is called when a notification is received. - This has to be overridden by any child class. - """ - return + Save the figure to file. + The default directory for writing the file is the same as the + directory where the script or notebook is running. - def render(self): - """ - At the end of figure creation, this function is called to request data from - all parent nodes and draw the figure. + Parameters + ---------- + filename: + Name of the output file. Possible file extensions are ``.jpg``, ``.png``, + ``.svg``, and ``.pdf``. """ - for node in self.graph_nodes.values(): - new_values = node.request_data() - self.update(new_values=new_values, key=node.id) + return self._view.canvas.save(filename, **kwargs) + + def update(self, *args, **kwargs): + return self._view.update(*args, **kwargs) + + def notify_view(self, *args, **kwargs): + return self._view.notify_view(*args, **kwargs) diff --git a/src/plopp/graphics/figure.py b/src/plopp/graphics/figure.py index dda7dcb1..cb9005bf 100644 --- a/src/plopp/graphics/figure.py +++ b/src/plopp/graphics/figure.py @@ -9,7 +9,7 @@ def figure1d(*args, style: Literal['line'] = 'line', **kwargs): """ Create a figure to represent one-dimensional data from one or more graph node(s). - By default, this will return a figure built from :class:`FigLine` (see the + By default, this will return a figure built from :class:`LineView` (see the documentation of this class for a list of available customization arguments). Parameters @@ -37,9 +37,9 @@ def figure1d(*args, style: Literal['line'] = 'line', **kwargs): """ if style == 'line': - from .figline import FigLine + from .lineview import LineView - return backends.figure1d(FigLine, *args, **kwargs) + return backends.figure1d(LineView, *args, **kwargs) raise ValueError(f'Unsupported style={style} for figure1d.') @@ -47,7 +47,7 @@ def figure1d(*args, style: Literal['line'] = 'line', **kwargs): def figure2d(*args, style: Literal['image'] = 'image', **kwargs): """ Create a figure to represent two-dimensional data from a graph node. - By default, this will return a figure built from :class:`FigImage` (see the + By default, this will return a figure built from :class:`ImageView` (see the documentation of this class for a list of available customization arguments). Parameters @@ -69,9 +69,9 @@ def figure2d(*args, style: Literal['image'] = 'image', **kwargs): """ if style == 'image': - from .figimage import FigImage + from .imageview import ImageView - return backends.figure2d(FigImage, *args, **kwargs) + return backends.figure2d(ImageView, *args, **kwargs) raise ValueError(f'Unsupported style={style} for figure2d.') @@ -101,8 +101,8 @@ def figure3d(*args, style: Literal['scatter'] = 'scatter', **kwargs): """ if style == 'scatter': - from .figscatter3d import FigScatter3d + from .scatter3dview import Scatter3dView - return backends.figure3d(FigScatter3d, *args, **kwargs) + return backends.figure3d(Scatter3dView, *args, **kwargs) raise ValueError(f'Unsupported style={style} for figure3d.') diff --git a/src/plopp/graphics/figimage.py b/src/plopp/graphics/imageview.py similarity index 96% rename from src/plopp/graphics/figimage.py rename to src/plopp/graphics/imageview.py index a3838709..05777dfb 100644 --- a/src/plopp/graphics/figimage.py +++ b/src/plopp/graphics/imageview.py @@ -6,14 +6,14 @@ import scipp as sc from .. import backends +from ..core import View from ..core.utils import make_compatible, name_with_unit -from .basefig import BaseFig from .colormapper import ColorMapper -class FigImage(BaseFig): +class ImageView(View): """ - Figure that makes a visual representation of two-dimensional data. + ImageView that makes a visual representation of two-dimensional data. It has a :class:`Canvas`, a :class:`ColorMapper` and a specialized ``update`` function that generates :class:`Image` artists. @@ -126,7 +126,7 @@ def update(self, new_values: sc.DataArray, key: str): The id of the node that sent the new data. """ if new_values.ndim != 2: - raise ValueError("FigImage can only be used to plot 2-D data.") + raise ValueError("ImageView can only be used to plot 2-D data.") xdim = new_values.dims[1] xcoord = new_values.coords[xdim] diff --git a/src/plopp/graphics/figline.py b/src/plopp/graphics/lineview.py similarity index 96% rename from src/plopp/graphics/figline.py rename to src/plopp/graphics/lineview.py index c4dca0f2..32173d58 100644 --- a/src/plopp/graphics/figline.py +++ b/src/plopp/graphics/lineview.py @@ -6,13 +6,13 @@ import scipp as sc from .. import backends +from ..core import View from ..core.utils import make_compatible, name_with_unit -from .basefig import BaseFig -class FigLine(BaseFig): +class LineView(View): """ - Figure that makes a visual representation of one-dimensional data. + View that makes a visual representation of one-dimensional data. It has a :class:`Canvas` and a specialized ``update`` function that generates :class:`Line` artists. @@ -120,7 +120,7 @@ def update(self, new_values: sc.DataArray, key: str): The id of the node that sent the new data. """ if new_values.ndim != 1: - raise ValueError("FigLine can only be used to plot 1-D data.") + raise ValueError("LineView can only be used to plot 1-D data.") xdim = new_values.dim xcoord = new_values.coords[xdim] diff --git a/src/plopp/graphics/figscatter3d.py b/src/plopp/graphics/scatter3dview.py similarity index 97% rename from src/plopp/graphics/figscatter3d.py rename to src/plopp/graphics/scatter3dview.py index 4bc3e5ff..6b3fd983 100644 --- a/src/plopp/graphics/figscatter3d.py +++ b/src/plopp/graphics/scatter3dview.py @@ -6,15 +6,15 @@ import scipp as sc from .. import backends +from ..core import View from ..core.utils import make_compatible from ..graphics import Camera -from .basefig import BaseFig from .colormapper import ColorMapper -class FigScatter3d(BaseFig): +class Scatter3dView(View): """ - Figure that makes a visual representation of three-dimensional scatter data. + View that makes a visual representation of three-dimensional scatter data. It has a :class:`Canvas`, a :class:`ColorMapper` and a specialized ``update`` function that generates :class:`PointCloud` artists. diff --git a/src/plopp/functions/__init__.py b/src/plopp/plotting/__init__.py similarity index 100% rename from src/plopp/functions/__init__.py rename to src/plopp/plotting/__init__.py diff --git a/src/plopp/functions/common.py b/src/plopp/plotting/common.py similarity index 100% rename from src/plopp/functions/common.py rename to src/plopp/plotting/common.py diff --git a/src/plopp/functions/inspector.py b/src/plopp/plotting/inspector.py similarity index 100% rename from src/plopp/functions/inspector.py rename to src/plopp/plotting/inspector.py diff --git a/src/plopp/functions/plot.py b/src/plopp/plotting/plot.py similarity index 100% rename from src/plopp/functions/plot.py rename to src/plopp/plotting/plot.py diff --git a/src/plopp/functions/scatter3d.py b/src/plopp/plotting/scatter3d.py similarity index 100% rename from src/plopp/functions/scatter3d.py rename to src/plopp/plotting/scatter3d.py diff --git a/src/plopp/functions/slicer.py b/src/plopp/plotting/slicer.py similarity index 100% rename from src/plopp/functions/slicer.py rename to src/plopp/plotting/slicer.py diff --git a/src/plopp/functions/superplot.py b/src/plopp/plotting/superplot.py similarity index 100% rename from src/plopp/functions/superplot.py rename to src/plopp/plotting/superplot.py diff --git a/src/plopp/widgets/drawing.py b/src/plopp/widgets/drawing.py index 8cbca3ad..2730c490 100644 --- a/src/plopp/widgets/drawing.py +++ b/src/plopp/widgets/drawing.py @@ -6,7 +6,8 @@ import scipp as sc -from ..core import Node, View, node +from ..backends.protocols import FigureLike +from ..core import Node, node from .tools import ToggleTool @@ -46,11 +47,11 @@ class DrawingTool(ToggleTool): def __init__( self, - figure: View, + figure: FigureLike, input_node: Node, tool: Any, func: Callable, - destination: Union[View, Node], + destination: Union[FigureLike, Node], get_artist_info: Callable, value: bool = False, **kwargs, @@ -80,7 +81,7 @@ def make_node(self, artist): output_node.name = f'Output node {len(self._output_nodes)}' self._output_nodes[nodeid] = output_node if self._destination_is_fig: - output_node.add_view(self._destination._fig) + output_node.add_view(self._destination._view) self._destination.update(new_values=output_node(), key=output_node.id) self._destination.artists[output_node.id].color = ( artist.color if hasattr(artist, 'color') else artist.edgecolor diff --git a/tests/backends/matplotlib/mpl_figure_test.py b/tests/backends/matplotlib/mpl_figure_test.py index af86fafb..fe124627 100644 --- a/tests/backends/matplotlib/mpl_figure_test.py +++ b/tests/backends/matplotlib/mpl_figure_test.py @@ -4,29 +4,29 @@ from plopp.backends.matplotlib import MatplotlibBackend from plopp.backends.matplotlib.interactive import InteractiveFig from plopp.backends.matplotlib.static import StaticFig -from plopp.graphics.figimage import FigImage -from plopp.graphics.figline import FigLine +from plopp.graphics.imageview import ImageView +from plopp.graphics.lineview import LineView def test_create_static_fig1d(): b = MatplotlibBackend() - fig = b.figure1d(FigConstructor=FigLine) + fig = b.figure1d(View=LineView) assert isinstance(fig, StaticFig) def test_create_interactive_fig1d(use_ipympl): b = MatplotlibBackend() - fig = b.figure1d(FigConstructor=FigLine) + fig = b.figure1d(View=LineView) assert isinstance(fig, InteractiveFig) def test_create_static_fig2d(): b = MatplotlibBackend() - fig = b.figure2d(FigConstructor=FigImage) + fig = b.figure2d(View=ImageView) assert isinstance(fig, StaticFig) def test_create_interactive_fig2d(use_ipympl): b = MatplotlibBackend() - fig = b.figure2d(FigConstructor=FigImage) + fig = b.figure2d(View=ImageView) assert isinstance(fig, InteractiveFig) diff --git a/tests/backends/matplotlib/mpl_figimage_test.py b/tests/backends/matplotlib/mpl_imageview_test.py similarity index 86% rename from tests/backends/matplotlib/mpl_figimage_test.py rename to tests/backends/matplotlib/mpl_imageview_test.py index 5d18ba34..9eaa03b3 100644 --- a/tests/backends/matplotlib/mpl_figimage_test.py +++ b/tests/backends/matplotlib/mpl_imageview_test.py @@ -7,12 +7,12 @@ from plopp import Node from plopp.data.testing import data_array -from plopp.graphics.figimage import FigImage +from plopp.graphics.imageview import ImageView def test_cbar(): da = data_array(ndim=2, binedges=True) - fig = FigImage(Node(da), cbar=False) + fig = ImageView(Node(da), cbar=False) assert fig.canvas.cax is None @@ -22,7 +22,7 @@ def test_update_on_one_mesh_changes_colors_on_second_mesh(): da2.coords['xx'] += sc.scalar(50.0, unit='m') a = Node(da1) b = Node(da2) - f = FigImage(a, b) + f = ImageView(a, b) old_b_colors = f.artists[b.id]._mesh.get_facecolors() a.func = lambda: da1 * 2.1 a.notify_children('updated a') @@ -42,7 +42,7 @@ def test_with_string_coord(): 'y': sc.arange('y', 5.0, unit='m'), }, ) - fig = FigImage(Node(da)) + fig = ImageView(Node(da)) assert [t.get_text() for t in fig.canvas.ax.get_xticklabels()] == strings @@ -55,7 +55,7 @@ def test_with_strings_as_bin_edges(): 'y': sc.arange('y', 6.0, unit='m'), }, ) - fig = FigImage(Node(da)) + fig = ImageView(Node(da)) assert [t.get_text() for t in fig.canvas.ax.get_xticklabels()] == strings @@ -68,16 +68,16 @@ def test_with_strings_as_bin_edges_other_coord_is_bin_centers(): 'y': sc.arange('y', 5.0, unit='m'), }, ) - fig = FigImage(Node(da)) + fig = ImageView(Node(da)) assert [t.get_text() for t in fig.canvas.ax.get_xticklabels()] == strings def test_kwargs_are_forwarded_to_artist(): da = data_array(ndim=2) - fig = FigImage(Node(da), rasterized=True) + fig = ImageView(Node(da), rasterized=True) artist = list(fig.artists.values())[0] assert artist._mesh.get_rasterized() - fig = FigImage(Node(da), rasterized=False) + fig = ImageView(Node(da), rasterized=False) artist = list(fig.artists.values())[0] assert not artist._mesh.get_rasterized() @@ -85,13 +85,13 @@ def test_kwargs_are_forwarded_to_artist(): def test_figsize(): da = data_array(ndim=2) size = (8.1, 8.3) - fig = FigImage(Node(da), figsize=size) + fig = ImageView(Node(da), figsize=size) assert np.allclose(fig.canvas.fig.get_size_inches(), size) def test_grid(): da = data_array(ndim=2) - fig = FigImage(Node(da), grid=True) + fig = ImageView(Node(da), grid=True) assert fig.canvas.ax.xaxis.get_gridlines()[0].get_visible() @@ -99,7 +99,7 @@ def test_ax(): fig, ax = plt.subplots() assert len(ax.collections) == 0 da = data_array(ndim=2) - _ = FigImage(Node(da), ax=ax) + _ = ImageView(Node(da), ax=ax) assert len(ax.collections) == 1 @@ -108,5 +108,5 @@ def test_cax(): cax = fig.add_axes([0.9, 0.02, 0.05, 0.98]) assert len(cax.collections) == 0 da = data_array(ndim=2) - _ = FigImage(Node(da), ax=ax, cax=cax) + _ = ImageView(Node(da), ax=ax, cax=cax) assert len(cax.collections) > 0 diff --git a/tests/backends/matplotlib/mpl_interactive_test.py b/tests/backends/matplotlib/mpl_interactive_test.py index 8637e0c4..61d38f34 100644 --- a/tests/backends/matplotlib/mpl_interactive_test.py +++ b/tests/backends/matplotlib/mpl_interactive_test.py @@ -4,30 +4,30 @@ from plopp import Node from plopp.backends.matplotlib.interactive import InteractiveFig from plopp.data.testing import data_array -from plopp.graphics.figimage import FigImage -from plopp.graphics.figline import FigLine +from plopp.graphics.imageview import ImageView +from plopp.graphics.lineview import LineView def test_logx_1d_toolbar_button(use_ipympl): da = data_array(ndim=1) - fig = InteractiveFig(FigLine, Node(da), scale={'xx': 'log'}) + fig = InteractiveFig(LineView, Node(da), scale={'xx': 'log'}) assert fig.toolbar['logx'].value def test_logy_1d_toolbar_button(use_ipympl): da = data_array(ndim=1) - fig = InteractiveFig(FigLine, Node(da), norm='log') + fig = InteractiveFig(LineView, Node(da), norm='log') assert fig.toolbar['logy'].value def test_logxy_2d_toolbar_buttons(use_ipympl): da = data_array(ndim=2) - fig = InteractiveFig(FigImage, Node(da), scale={'xx': 'log', 'yy': 'log'}) + fig = InteractiveFig(ImageView, Node(da), scale={'xx': 'log', 'yy': 'log'}) assert fig.toolbar['logx'].value assert fig.toolbar['logy'].value def test_log_norm_2d_toolbar_button(use_ipympl): da = data_array(ndim=2) - fig = InteractiveFig(FigImage, Node(da), norm='log') + fig = InteractiveFig(ImageView, Node(da), norm='log') assert fig.toolbar['lognorm'].value diff --git a/tests/backends/matplotlib/mpl_figline_test.py b/tests/backends/matplotlib/mpl_lineview_test.py similarity index 84% rename from tests/backends/matplotlib/mpl_figline_test.py rename to tests/backends/matplotlib/mpl_lineview_test.py index 17a2f6ec..273d0409 100644 --- a/tests/backends/matplotlib/mpl_figline_test.py +++ b/tests/backends/matplotlib/mpl_lineview_test.py @@ -7,7 +7,7 @@ from plopp import Node from plopp.data.testing import data_array -from plopp.graphics.figline import FigLine +from plopp.graphics.lineview import LineView def test_with_string_coord(): @@ -16,7 +16,7 @@ def test_with_string_coord(): data=sc.arange('x', 5.0), coords={'x': sc.array(dims=['x'], values=strings, unit='m')}, ) - fig = FigLine(Node(da)) + fig = LineView(Node(da)) assert [t.get_text() for t in fig.canvas.ax.get_xticklabels()] == strings @@ -26,20 +26,20 @@ def test_with_strings_as_bin_edges(): data=sc.arange('x', 5.0), coords={'x': sc.array(dims=['x'], values=strings, unit='m')}, ) - fig = FigLine(Node(da)) + fig = LineView(Node(da)) assert [t.get_text() for t in fig.canvas.ax.get_xticklabels()] == strings def test_figsize(): da = data_array(ndim=1) size = (6.1, 3.3) - fig = FigLine(Node(da), figsize=size) + fig = LineView(Node(da), figsize=size) assert np.allclose(fig.canvas.fig.get_size_inches(), size) def test_grid(): da = data_array(ndim=1) - fig = FigLine(Node(da), grid=True) + fig = LineView(Node(da), grid=True) assert fig.canvas.ax.xaxis.get_gridlines()[0].get_visible() @@ -47,5 +47,5 @@ def test_ax(): fig, ax = plt.subplots() assert len(ax.lines) == 0 da = data_array(ndim=1) - _ = FigLine(Node(da), ax=ax) + _ = LineView(Node(da), ax=ax) assert len(ax.lines) > 0 diff --git a/tests/backends/matplotlib/mpl_utils_test.py b/tests/backends/matplotlib/mpl_utils_test.py index 94dfd23f..6e508148 100644 --- a/tests/backends/matplotlib/mpl_utils_test.py +++ b/tests/backends/matplotlib/mpl_utils_test.py @@ -6,12 +6,12 @@ from plopp.backends.matplotlib.static import StaticFig from plopp.backends.matplotlib.utils import copy_figure from plopp.data.testing import data_array -from plopp.graphics.figline import FigLine +from plopp.graphics.lineview import LineView def do_test_copy(Fig): da = data_array(ndim=1) - original = Fig(FigLine, Node(da)) + original = Fig(LineView, Node(da)) copy = copy_figure(original) assert original.graph_nodes.keys() == copy.graph_nodes.keys() assert original.artists.keys() == copy.artists.keys() @@ -20,7 +20,7 @@ def do_test_copy(Fig): def do_test_copy_keeps_kwargs(Fig): da = data_array(ndim=1) original = Fig( - FigLine, + LineView, Node(da), scale={'xx': 'log'}, norm='log', diff --git a/tests/backends/plotly/plotly_figure_test.py b/tests/backends/plotly/plotly_figure_test.py index 503306d6..58ab6e16 100644 --- a/tests/backends/plotly/plotly_figure_test.py +++ b/tests/backends/plotly/plotly_figure_test.py @@ -6,25 +6,25 @@ import plopp as pp from plopp.backends.plotly.figure import Figure from plopp.data.testing import data_array -from plopp.graphics.figline import FigLine +from plopp.graphics.lineview import LineView pytest.importorskip("plotly") def test_creation(): da = data_array(ndim=1) - fig = Figure(FigLine, pp.Node(da)) + fig = Figure(LineView, pp.Node(da)) assert fig.canvas.xlabel == f'xx [{da.coords["xx"].unit}]' assert fig.canvas.ylabel == f'[{da.unit}]' def test_logx_1d_toolbar_button(): da = data_array(ndim=1) - fig = Figure(FigLine, pp.Node(da), scale={'xx': 'log'}) + fig = Figure(LineView, pp.Node(da), scale={'xx': 'log'}) assert fig.toolbar['logx'].value def test_logy_1d_toolbar_button(): da = data_array(ndim=1) - fig = Figure(FigLine, pp.Node(da), norm='log') + fig = Figure(LineView, pp.Node(da), norm='log') assert fig.toolbar['logy'].value diff --git a/tests/backends/pythreejs/pythreejs_figure_test.py b/tests/backends/pythreejs/pythreejs_figure_test.py index fb5366af..775fb66b 100644 --- a/tests/backends/pythreejs/pythreejs_figure_test.py +++ b/tests/backends/pythreejs/pythreejs_figure_test.py @@ -9,18 +9,18 @@ from plopp import Node from plopp.backends.pythreejs.figure import Figure from plopp.data.testing import scatter -from plopp.graphics.figscatter3d import FigScatter3d +from plopp.graphics.scatter3dview import Scatter3dView def test_log_norm_3d_toolbar_button(): da = scatter() - fig = Figure(FigScatter3d, Node(da), x='x', y='y', z='z', norm='log') + fig = Figure(Scatter3dView, Node(da), x='x', y='y', z='z', norm='log') assert fig.toolbar['lognorm'].value def test_save_to_html(): da = scatter() - fig = Figure(FigScatter3d, Node(da), x='x', y='y', z='z', norm='log') + fig = Figure(Scatter3dView, Node(da), x='x', y='y', z='z', norm='log') with tempfile.TemporaryDirectory() as path: fname = os.path.join(path, 'plopp_fig3d.html') fig.save(filename=fname) @@ -29,6 +29,6 @@ def test_save_to_html(): def test_save_to_html_with_bad_extension_raises(): da = scatter() - fig = Figure(FigScatter3d, Node(da), x='x', y='y', z='z', norm='log') + fig = Figure(Scatter3dView, Node(da), x='x', y='y', z='z', norm='log') with pytest.raises(ValueError, match=r'File extension must be \.html'): fig.save(filename='plopp_fig3d.png') diff --git a/tests/graphics/figimage_test.py b/tests/graphics/imageview_test.py similarity index 82% rename from tests/graphics/figimage_test.py rename to tests/graphics/imageview_test.py index 158d86b9..6d198a55 100644 --- a/tests/graphics/figimage_test.py +++ b/tests/graphics/imageview_test.py @@ -6,16 +6,16 @@ from plopp import Node from plopp.data.testing import data_array -from plopp.graphics.figimage import FigImage +from plopp.graphics.imageview import ImageView def test_empty(): - fig = FigImage() + fig = ImageView() assert len(fig.artists) == 0 def test_update(): - fig = FigImage() + fig = ImageView() assert len(fig.artists) == 0 da = data_array(ndim=2) key = 'data2d' @@ -24,23 +24,27 @@ def test_update(): def test_update_not_2d_raises(): - fig = FigImage() - with pytest.raises(ValueError, match="FigImage can only be used to plot 2-D data."): + fig = ImageView() + with pytest.raises( + ValueError, match="ImageView can only be used to plot 2-D data." + ): fig.update(data_array(ndim=1), key='data1d') - with pytest.raises(ValueError, match="FigImage can only be used to plot 2-D data."): + with pytest.raises( + ValueError, match="ImageView can only be used to plot 2-D data." + ): fig.update(data_array(ndim=3), key='data3d') def test_create_with_node(): da = data_array(ndim=2) - fig = FigImage(Node(da)) + fig = ImageView(Node(da)) assert len(fig.artists) == 1 assert sc.identical(list(fig.artists.values())[0]._data, da) def test_create_with_bin_edges(): da = data_array(ndim=2, binedges=True) - fig = FigImage(Node(da)) + fig = ImageView(Node(da)) assert len(fig.artists) == 1 assert sc.identical(list(fig.artists.values())[0]._data, da) @@ -48,19 +52,19 @@ def test_create_with_bin_edges(): def test_create_with_only_one_bin_edge_coord(): da = data_array(ndim=2, binedges=True) da.coords['xx'] = sc.midpoints(da.coords['xx']) - fig = FigImage(Node(da)) + fig = ImageView(Node(da)) assert len(fig.artists) == 1 assert sc.identical(list(fig.artists.values())[0]._data, da) def test_log_norm(): - fig = FigImage(norm='log') + fig = ImageView(norm='log') assert fig.colormapper.norm == 'log' def test_crop(): da = data_array(ndim=2, binedges=True) - fig = FigImage(Node(da)) + fig = ImageView(Node(da)) assert fig.canvas.xrange == (da.meta['xx'].min().value, da.meta['xx'].max().value) assert fig.canvas.yrange == (da.meta['yy'].min().value, da.meta['yy'].max().value) xmin = sc.scalar(2.1, unit='m') @@ -78,7 +82,7 @@ def test_crop_no_variable(): xmax = 102.0 ymin = 5.5 ymax = 22.3 - fig = FigImage( + fig = ImageView( Node(da), crop={'xx': {'min': xmin, 'max': xmax}, 'yy': {'min': ymin, 'max': ymax}}, ) @@ -90,14 +94,14 @@ def test_raises_for_new_data_with_incompatible_dimension(): a = data_array(ndim=2) b = a.rename(xx='zz') with pytest.raises(sc.DimensionError): - FigImage(Node(a), Node(b)) + ImageView(Node(a), Node(b)) def test_raises_for_new_data_with_incompatible_unit(): a = data_array(ndim=2) b = a * a with pytest.raises(sc.UnitError): - FigImage(Node(a), Node(b)) + ImageView(Node(a), Node(b)) def test_raises_for_new_data_with_incompatible_coord_unit(): @@ -105,7 +109,7 @@ def test_raises_for_new_data_with_incompatible_coord_unit(): b = a.copy() b.coords['xx'] = a.coords['xx'] * a.coords['xx'] with pytest.raises(sc.UnitError): - FigImage(Node(a), Node(b)) + ImageView(Node(a), Node(b)) def test_converts_new_data_units(): @@ -113,7 +117,7 @@ def test_converts_new_data_units(): b = data_array(ndim=2, unit='cm') anode = Node(a) bnode = Node(b) - fig = FigImage(anode, bnode) + fig = ImageView(anode, bnode) assert sc.identical(fig.artists[anode.id]._data, a) assert sc.identical(fig.artists[bnode.id]._data, b.to(unit='m')) @@ -124,7 +128,7 @@ def test_converts_new_data_coordinate_units(): b.coords['xx'].unit = 'cm' anode = Node(a) bnode = Node(b) - fig = FigImage(anode, bnode) + fig = ImageView(anode, bnode) assert sc.identical(fig.artists[anode.id]._data, a) c = b.copy() c.coords['xx'] = c.coords['xx'].to(unit='m') @@ -133,7 +137,7 @@ def test_converts_new_data_coordinate_units(): def test_colorbar_label_has_correct_unit(): da = data_array(ndim=2, unit='K') - fig = FigImage(Node(da)) + fig = ImageView(Node(da)) assert fig.canvas.cblabel == '[K]' @@ -141,7 +145,7 @@ def test_colorbar_label_has_correct_name(): da = data_array(ndim=2, unit='K') name = 'My Experimental Data' da.name = name - fig = FigImage(Node(da)) + fig = ImageView(Node(da)) assert fig.canvas.cblabel == name + ' [K]' @@ -150,5 +154,5 @@ def test_colorbar_label_has_no_name_with_multiple_artists(): b = 3.3 * a a.name = 'A data' b.name = 'B data' - fig = FigImage(Node(a), Node(b)) + fig = ImageView(Node(a), Node(b)) assert fig.canvas.cblabel == '[K]' diff --git a/tests/graphics/figline_test.py b/tests/graphics/lineview_test.py similarity index 81% rename from tests/graphics/figline_test.py rename to tests/graphics/lineview_test.py index 4c343a4a..56eb5d53 100644 --- a/tests/graphics/figline_test.py +++ b/tests/graphics/lineview_test.py @@ -7,16 +7,16 @@ from plopp import Node from plopp.data.testing import data_array -from plopp.graphics.figline import FigLine +from plopp.graphics.lineview import LineView def test_empty(): - fig = FigLine() + fig = LineView() assert len(fig.artists) == 0 def test_update(): - fig = FigLine() + fig = LineView() assert len(fig.artists) == 0 da = data_array(ndim=1) key = 'data1d' @@ -25,16 +25,16 @@ def test_update(): def test_update_not_1d_raises(): - fig = FigLine() - with pytest.raises(ValueError, match="FigLine can only be used to plot 1-D data."): + fig = LineView() + with pytest.raises(ValueError, match="LineView can only be used to plot 1-D data."): fig.update(data_array(ndim=2), key='data2d') - with pytest.raises(ValueError, match="FigLine can only be used to plot 1-D data."): + with pytest.raises(ValueError, match="LineView can only be used to plot 1-D data."): fig.update(data_array(ndim=3), key='data3d') def test_create_with_node(): da = data_array(ndim=1) - fig = FigLine(Node(da)) + fig = LineView(Node(da)) assert len(fig.artists) == 1 line = list(fig.artists.values())[0] assert sc.identical(line._data, da) @@ -43,18 +43,18 @@ def test_create_with_node(): def test_with_errorbars(): da = data_array(ndim=1, variances=True) - fig = FigLine(Node(da)) + fig = LineView(Node(da)) assert len(fig.artists) == 1 line = list(fig.artists.values())[0] assert line._error is not None - fig = FigLine(Node(da), errorbars=False) + fig = LineView(Node(da), errorbars=False) line = list(fig.artists.values())[0] assert line._error is None def test_with_binedges(): da = data_array(ndim=1, binedges=True) - fig = FigLine(Node(da)) + fig = LineView(Node(da)) assert len(fig.artists) == 1 line = list(fig.artists.values())[0] assert sc.identical(line._data, da) @@ -64,15 +64,15 @@ def test_with_binedges(): def test_log_norm(): - fig = FigLine() + fig = LineView() assert fig.canvas.yscale == 'linear' - fig = FigLine(norm='log') + fig = LineView(norm='log') assert fig.canvas.yscale == 'log' def test_crop(): da = data_array(ndim=1) - fig = FigLine(Node(da)) + fig = LineView(Node(da)) assert fig.canvas.xmin < da.meta['xx'].min().value assert fig.canvas.xmax > da.meta['xx'].max().value xmin = sc.scalar(2.1, unit='m') @@ -87,13 +87,13 @@ def test_crop_no_variable(): da = data_array(ndim=1) xmin = 2.1 xmax = 33.4 - fig = FigLine(Node(da), crop={'xx': {'min': xmin, 'max': xmax}}) + fig = LineView(Node(da), crop={'xx': {'min': xmin, 'max': xmax}}) assert fig.canvas.xrange == (xmin, xmax) def test_update_grows_limits(): da = data_array(ndim=1) - fig = FigLine(Node(da)) + fig = LineView(Node(da)) old_lims = fig.canvas.yrange key = list(fig.artists.keys())[0] fig.update(da * 2.5, key=key) @@ -104,7 +104,7 @@ def test_update_grows_limits(): def test_update_does_shrink_limits_if_auto_mode(): da = data_array(ndim=1) - fig = FigLine(Node(da), autoscale='auto') + fig = LineView(Node(da), autoscale='auto') old_lims = fig.canvas.yrange key = list(fig.artists.keys())[0] const = 0.5 @@ -116,7 +116,7 @@ def test_update_does_shrink_limits_if_auto_mode(): def test_update_does_not_shrink_limits_if_grow_mode(): da = data_array(ndim=1) - fig = FigLine(Node(da), autoscale='grow') + fig = LineView(Node(da), autoscale='grow') old_lims = fig.canvas.yrange key = list(fig.artists.keys())[0] fig.update(da * 0.5, key=key) @@ -127,25 +127,25 @@ def test_update_does_not_shrink_limits_if_grow_mode(): def test_vmin(): da = data_array(ndim=1) - fig = FigLine(Node(da), vmin=sc.scalar(-0.5, unit='m/s')) + fig = LineView(Node(da), vmin=sc.scalar(-0.5, unit='m/s')) assert fig.canvas.ymin == -0.5 def test_vmin_unit_mismatch_raises(): da = data_array(ndim=1) with pytest.raises(sc.UnitError): - _ = FigLine(Node(da), vmin=sc.scalar(-0.5, unit='m')) + _ = LineView(Node(da), vmin=sc.scalar(-0.5, unit='m')) def test_vmax(): da = data_array(ndim=1) - fig = FigLine(Node(da), vmax=sc.scalar(0.68, unit='m/s')) + fig = LineView(Node(da), vmax=sc.scalar(0.68, unit='m/s')) assert fig.canvas.ymax == 0.68 def test_vmin_vmax(): da = data_array(ndim=1) - fig = FigLine( + fig = LineView( Node(da), vmin=sc.scalar(-0.5, unit='m/s'), vmax=sc.scalar(0.68, unit='m/s'), @@ -155,7 +155,7 @@ def test_vmin_vmax(): def test_vmin_vmax_no_variable(): da = data_array(ndim=1) - fig = FigLine(Node(da), vmin=-0.5, vmax=0.68) + fig = LineView(Node(da), vmin=-0.5, vmax=0.68) assert np.allclose(fig.canvas.yrange, [-0.5, 0.68]) @@ -163,14 +163,14 @@ def test_raises_for_new_data_with_incompatible_dimension(): x = data_array(ndim=1) y = x.rename(xx='yy') with pytest.raises(sc.DimensionError): - FigLine(Node(x), Node(y)) + LineView(Node(x), Node(y)) def test_raises_for_new_data_with_incompatible_unit(): a = data_array(ndim=1) b = a * a with pytest.raises(sc.UnitError): - FigLine(Node(a), Node(b)) + LineView(Node(a), Node(b)) def test_raises_for_new_data_with_incompatible_coord_unit(): @@ -178,7 +178,7 @@ def test_raises_for_new_data_with_incompatible_coord_unit(): b = a.copy() b.coords['xx'] = a.coords['xx'] * a.coords['xx'] with pytest.raises(sc.UnitError): - FigLine(Node(a), Node(b)) + LineView(Node(a), Node(b)) def test_converts_new_data_units(): @@ -186,7 +186,7 @@ def test_converts_new_data_units(): b = data_array(ndim=1, unit='cm') anode = Node(a) bnode = Node(b) - fig = FigLine(anode, bnode) + fig = LineView(anode, bnode) assert sc.identical(fig.artists[anode.id]._data, a) assert sc.identical(fig.artists[bnode.id]._data, b.to(unit='m')) @@ -197,7 +197,7 @@ def test_converts_new_data_coordinate_units(): b.coords['xx'].unit = 'cm' anode = Node(a) bnode = Node(b) - fig = FigLine(anode, bnode) + fig = LineView(anode, bnode) assert sc.identical(fig.artists[anode.id]._data, a) c = b.copy() c.coords['xx'] = c.coords['xx'].to(unit='m') @@ -215,6 +215,6 @@ def test_converts_new_data_units_integers(): ) anode = Node(a) bnode = Node(b) - fig = FigLine(anode, bnode) + fig = LineView(anode, bnode) assert sc.identical(fig.artists[anode.id]._data, a) assert sc.identical(fig.artists[bnode.id]._data, b.to(unit='m', dtype=float)) diff --git a/tests/graphics/figscatter3d_test.py b/tests/graphics/scatter3dview_test.py similarity index 77% rename from tests/graphics/figscatter3d_test.py rename to tests/graphics/scatter3dview_test.py index 3fbf77a2..37124553 100644 --- a/tests/graphics/figscatter3d_test.py +++ b/tests/graphics/scatter3dview_test.py @@ -6,12 +6,12 @@ from plopp import Node from plopp.data.testing import scatter -from plopp.graphics.figscatter3d import FigScatter3d +from plopp.graphics.scatter3dview import Scatter3dView def test_creation(): da = scatter() - fig = FigScatter3d(Node(da), x='x', y='y', z='z') + fig = Scatter3dView(Node(da), x='x', y='y', z='z') assert len(fig.artists) == 1 key = list(fig.artists.keys())[0] assert sc.identical(fig.artists[key]._data, da) @@ -19,7 +19,7 @@ def test_creation(): def test_update(): da = scatter() - fig = FigScatter3d(Node(da), x='x', y='y', z='z') + fig = Scatter3dView(Node(da), x='x', y='y', z='z') assert len(fig.artists) == 1 key = list(fig.artists.keys())[0] fig.update(da * 3.3, key=key) @@ -28,7 +28,7 @@ def test_update(): def test_log_norm(): da = scatter() - fig = FigScatter3d(Node(da), x='x', y='y', z='z', norm='log') + fig = Scatter3dView(Node(da), x='x', y='y', z='z', norm='log') assert fig.colormapper.norm == 'log' @@ -37,14 +37,14 @@ def test_raises_for_new_data_with_incompatible_coordinate(): b = scatter() b.coords['t'] = b.coords.pop('x') with pytest.raises(KeyError): - FigScatter3d(Node(a), Node(b), x='x', y='y', z='z') + Scatter3dView(Node(a), Node(b), x='x', y='y', z='z') def test_raises_for_new_data_with_incompatible_unit(): a = scatter() b = a * a with pytest.raises(sc.UnitError): - FigScatter3d(Node(a), Node(b), x='x', y='y', z='z') + Scatter3dView(Node(a), Node(b), x='x', y='y', z='z') def test_raises_for_new_data_with_incompatible_coord_unit(): @@ -52,7 +52,7 @@ def test_raises_for_new_data_with_incompatible_coord_unit(): b = a.copy() b.coords['x'] = a.coords['x'] * a.coords['x'] with pytest.raises(sc.UnitError): - FigScatter3d(Node(a), Node(b), x='x', y='y', z='z') + Scatter3dView(Node(a), Node(b), x='x', y='y', z='z') def test_converts_new_data_units(): @@ -62,7 +62,7 @@ def test_converts_new_data_units(): b.unit = 'cm' anode = Node(a) bnode = Node(b) - fig = FigScatter3d(anode, bnode, x='x', y='y', z='z') + fig = Scatter3dView(anode, bnode, x='x', y='y', z='z') assert sc.identical(fig.artists[anode.id]._data, a) assert sc.identical(fig.artists[bnode.id]._data, b.to(unit='m')) @@ -75,7 +75,7 @@ def test_converts_new_data_coordinate_units(): b.coords['x'] = xcoord anode = Node(a) bnode = Node(b) - fig = FigScatter3d(anode, bnode, x='x', y='y', z='z') + fig = Scatter3dView(anode, bnode, x='x', y='y', z='z') assert sc.identical(fig.artists[anode.id]._data, a) c = b.copy() c.coords['x'] = c.coords['x'].to(unit='m') diff --git a/tests/functions/common_test.py b/tests/plotting/common_test.py similarity index 97% rename from tests/functions/common_test.py rename to tests/plotting/common_test.py index b1384205..c0625641 100644 --- a/tests/functions/common_test.py +++ b/tests/plotting/common_test.py @@ -6,7 +6,7 @@ import scipp as sc from plopp.data.testing import data_array -from plopp.functions.common import preprocess +from plopp.plotting.common import preprocess def test_preprocess_raises_ValueError_when_given_binned_data(): diff --git a/tests/functions/inspector_test.py b/tests/plotting/inspector_test.py similarity index 100% rename from tests/functions/inspector_test.py rename to tests/plotting/inspector_test.py diff --git a/tests/functions/plot_test.py b/tests/plotting/plot_test.py similarity index 98% rename from tests/functions/plot_test.py rename to tests/plotting/plot_test.py index 66d87bb0..74340d5b 100644 --- a/tests/functions/plot_test.py +++ b/tests/plotting/plot_test.py @@ -157,7 +157,7 @@ def test_kwarg_scale(): def test_kwarg_cmap(): da = data_array(ndim=2) p = pp.plot(da, cmap='magma') - assert p._fig.colormapper.cmap.name == 'magma' + assert p._view.colormapper.cmap.name == 'magma' def test_kwarg_scale_2d(): @@ -346,7 +346,7 @@ def test_plot_xarray_dataset(): assert p.canvas.dims['x'] == 'time' assert p.canvas.units['x'] == 'dimensionless' assert p.canvas.units['y'] == 'dimensionless' - assert len(p._fig.artists) == 2 + assert len(p._view.artists) == 2 def test_plot_pandas_series(): @@ -357,7 +357,7 @@ def test_plot_pandas_series(): assert p.canvas.dims['x'] == 'row' assert p.canvas.units['x'] == 'dimensionless' assert p.canvas.units['y'] == 'dimensionless' - assert list(p._fig.artists.values())[0].label == 'MyDataSeries' + assert list(p._view.artists.values())[0].label == 'MyDataSeries' def test_plot_pandas_dataframe(): @@ -375,4 +375,4 @@ def test_plot_pandas_dataframe(): assert p.canvas.dims['x'] == 'row' assert p.canvas.units['x'] == 'dimensionless' assert p.canvas.units['y'] == 'dimensionless' - assert len(p._fig.artists) == 4 + assert len(p._view.artists) == 4 diff --git a/tests/functions/scatter3d_test.py b/tests/plotting/scatter3d_test.py similarity index 100% rename from tests/functions/scatter3d_test.py rename to tests/plotting/scatter3d_test.py diff --git a/tests/functions/slicer_test.py b/tests/plotting/slicer_test.py similarity index 94% rename from tests/functions/slicer_test.py rename to tests/plotting/slicer_test.py index 65ea28ef..0b600abc 100644 --- a/tests/functions/slicer_test.py +++ b/tests/plotting/slicer_test.py @@ -5,7 +5,7 @@ import scipp as sc from plopp.data.testing import data_array, dataset -from plopp.functions.slicer import Slicer +from plopp.plotting.slicer import Slicer def test_creation_keep_two_dims(): @@ -116,8 +116,8 @@ def test_autoscale_fixed(): data=sc.arange('x', 5 * 10 * 20).fold(dim='x', sizes={'z': 20, 'y': 10, 'x': 5}) ) sl = Slicer(da, keep=['y', 'x'], autoscale='fixed') - assert sl.figure._fig.colormapper.vmin == 0 - assert sl.figure._fig.colormapper.vmax == 5 * 10 * 20 - 1 + assert sl.figure._view.colormapper.vmin == 0 + assert sl.figure._view.colormapper.vmax == 5 * 10 * 20 - 1 sl.slider.controls['z']['slider'].value = 5 - assert sl.figure._fig.colormapper.vmin == 0 - assert sl.figure._fig.colormapper.vmax == 5 * 10 * 20 - 1 + assert sl.figure._view.colormapper.vmin == 0 + assert sl.figure._view.colormapper.vmax == 5 * 10 * 20 - 1 diff --git a/tests/functions/superplot_test.py b/tests/plotting/superplot_test.py similarity index 97% rename from tests/functions/superplot_test.py rename to tests/plotting/superplot_test.py index fc91d85a..28b1e99b 100644 --- a/tests/functions/superplot_test.py +++ b/tests/plotting/superplot_test.py @@ -4,7 +4,7 @@ import scipp as sc from plopp.data.testing import data_array -from plopp.functions.superplot import Superplot +from plopp.plotting.superplot import Superplot def test_creation(): diff --git a/tests/widgets/cut3d_test.py b/tests/widgets/cut3d_test.py index 93928e0b..7d6b77dc 100644 --- a/tests/widgets/cut3d_test.py +++ b/tests/widgets/cut3d_test.py @@ -3,13 +3,13 @@ from plopp import Node from plopp.data.testing import scatter -from plopp.graphics.figscatter3d import FigScatter3d +from plopp.graphics.scatter3dview import Scatter3dView from plopp.widgets import TriCutTool def test_show_hide_cuts(): da = scatter() - fig = FigScatter3d(Node(da), x='x', y='y', z='z') + fig = Scatter3dView(Node(da), x='x', y='y', z='z') tri = TriCutTool(fig) assert len(fig.artists) == 1 tri.cut_x.button.value = True @@ -28,7 +28,7 @@ def test_show_hide_cuts(): def test_move_cut(): da = scatter() - fig = FigScatter3d(Node(da), x='x', y='y', z='z') + fig = Scatter3dView(Node(da), x='x', y='y', z='z') tri = TriCutTool(fig) tri.cut_x.button.value = True assert tri.cut_x.outline.position[0] == tri.cut_x.slider.value @@ -42,7 +42,7 @@ def test_move_cut(): def test_cut_thickness(): da = scatter() - fig = FigScatter3d(Node(da), x='x', y='y', z='z') + fig = Scatter3dView(Node(da), x='x', y='y', z='z') tri = TriCutTool(fig) tri.cut_x.button.value = True pts = list(fig.artists.values())[-1] @@ -60,7 +60,7 @@ def test_cut_thickness(): def test_empty_cut(): da = scatter() - fig = FigScatter3d(Node(da), x='x', y='y', z='z') + fig = Scatter3dView(Node(da), x='x', y='y', z='z') tri = TriCutTool(fig) assert len(fig.artists) == 1 tri.cut_y.button.value = True