Skip to content
Open
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
44 changes: 27 additions & 17 deletions src/plopp/backends/matplotlib/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ class Canvas:
The label for the y axis.
norm:
Set to ``'log'`` for a logarithmic y-axis (legacy, prefer ``logy`` instead).
hide_log_buttons:
If ``True``, hide the buttons for toggling logarithmic scales on the axes.
"""

def __init__(
Expand All @@ -191,6 +193,7 @@ def __init__(
ylabel: str | None = None,
norm: Literal['linear', 'log'] | None = None,
autoscale_axes: Callable | None = None,
hide_log_buttons: bool = False,
**ignored,
):
# Note on the `**ignored`` keyword arguments: the figure which owns the canvas
Expand Down Expand Up @@ -256,26 +259,33 @@ def __init__(
self.fig.canvas.toolbar_visible = False
self.fig.canvas.header_visible = False

args = {"transform": self.ax.transAxes, "ha": "right", "va": "top"}
self._logx_button = CanvasToggleButton(
ax=self.ax, label="logX", position=(0.985, -0.02), **args
)
self._logy_button = CanvasToggleButton(
ax=self.ax, label="logY", position=(-0.015, 0.98), **args
)

if self.cax is not None:
args = {"transform": self.cax.transAxes, "ha": "center"}
self._logc_button = CanvasToggleButton(
ax=self.cax, label="log", position=(0.5, 0.98), va="top", **args
if not hide_log_buttons:
args = {"transform": self.ax.transAxes, "ha": "right", "va": "top"}
self._logx_button = CanvasToggleButton(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the attributes on self optional now? How does the rest of the class cope with this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff is misleading, the self._logx_button are set to None further up.

ax=self.ax, label="logX", position=(0.985, -0.02), **args
)
self._fitc_button = CanvasToggleButton(
ax=self.cax, label="fit", position=(0.5, 0.02), va="bottom", **args
self._logy_button = CanvasToggleButton(
ax=self.ax, label="logY", position=(-0.015, 0.98), **args
)

self.fig.canvas.mpl_connect("figure_enter_event", self._on_mouse_enter)
self.fig.canvas.mpl_connect("figure_leave_event", self._on_mouse_leave)
self.fig.canvas.mpl_connect("button_press_event", self._on_log_button_click)
if self.cax is not None:
args = {"transform": self.cax.transAxes, "ha": "center"}
self._logc_button = CanvasToggleButton(
ax=self.cax, label="log", position=(0.5, 0.98), va="top", **args
)
self._fitc_button = CanvasToggleButton(
ax=self.cax,
label="fit",
position=(0.5, 0.02),
va="bottom",
**args,
)

self.fig.canvas.mpl_connect("figure_enter_event", self._on_mouse_enter)
self.fig.canvas.mpl_connect("figure_leave_event", self._on_mouse_leave)
self.fig.canvas.mpl_connect(
"button_press_event", self._on_log_button_click
)

if logx:
self.xscale = 'log'
Expand Down
13 changes: 11 additions & 2 deletions src/plopp/graphics/colormapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class ColorMapper:
The maximum value for the colorscale range. If a number (without a unit) is
supplied, it is assumed that the unit is the same as the data unit.
This is an old parameter name. Prefer using ``cmax`` instead.
hide_log_buttons:
If ``True``, the interactive log buttons will be hidden.
"""

def __init__(
Expand All @@ -154,6 +156,7 @@ def __init__(
norm: Literal['linear', 'log'] | None = None,
vmin: sc.Variable | float | None = None,
vmax: sc.Variable | float | None = None,
hide_log_buttons: bool = False,
):
cmin = parse_mutually_exclusive(vmin=vmin, cmin=cmin)
cmax = parse_mutually_exclusive(vmax=vmax, cmax=cmax)
Expand Down Expand Up @@ -193,6 +196,7 @@ def __init__(
self.changed = False
self.artists = {}
self.widget = None
self._hide_log_buttons = hide_log_buttons

if cbar:
if self.cax is None:
Expand Down Expand Up @@ -223,11 +227,16 @@ def to_widget(self):
"""
Convert the colorbar into a widget for use with other ``ipywidgets``.
"""
from ..widgets.hoverbutton import HoverButtonWidget
from ..widgets.hoverbutton import HoverButtonWidget, PlainImageWidget

if self._hide_log_buttons:
self.widget = PlainImageWidget()
self._update_colorbar_widget()
return self.widget

self.widget = HoverButtonWidget(log_value=self._logc)
self._update_colorbar_widget()
self.widget.on_log_button_click(self.toggle_norm)
self._update_colorbar_widget()

def fit():
self.autoscale()
Expand Down
3 changes: 3 additions & 0 deletions src/plopp/graphics/graphicalview.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def __init__(
zlabel: str | None = None,
clabel: str | None = None,
nan_color: str | None = None,
hide_log_buttons: bool = False,
**kwargs,
):
super().__init__(*nodes)
Expand Down Expand Up @@ -123,6 +124,7 @@ def __init__(
zlabel=zlabel,
norm=norm if len(dims) == 1 else None,
autoscale_axes=self.autoscale,
hide_log_buttons=hide_log_buttons,
)

if colormapper:
Expand All @@ -141,6 +143,7 @@ def __init__(
canvas=self.canvas,
figsize=getattr(self.canvas, "figsize", None),
nan_color=nan_color,
hide_log_buttons=hide_log_buttons,
)
self._kwargs['colormapper'] = self.colormapper
if self._autoscale:
Expand Down
5 changes: 5 additions & 0 deletions src/plopp/plotting/_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def inspector(
errorbars: Literal['band', 'bar', True, False] = True,
figsize: tuple[float, float] | None = None,
grid: bool = False,
hide_log_buttons: bool = False,
legend: bool | tuple[float, float] = True,
logc: bool | None = None,
mask_cmap: str = 'gray',
Expand Down Expand Up @@ -252,6 +253,8 @@ def inspector(
The width and height of the figure, in inches.
grid:
Show grid if ``True``.
hide_log_buttons:
If ``True``, the interactive log buttons will be hidden.
legend:
Show legend if ``True``. If ``legend`` is a tuple, it should contain the
``(x, y)`` coordinates of the legend's anchor point in axes coordinates
Expand Down Expand Up @@ -318,6 +321,7 @@ def inspector(
autoscale=autoscale,
errorbars=errorbars,
grid=grid,
hide_log_buttons=hide_log_buttons,
legend=legend,
mask_color=mask_color,
xmax=xmax,
Expand Down Expand Up @@ -357,6 +361,7 @@ def inspector(
cmin=cmin,
figsize=figsize,
grid=grid,
hide_log_buttons=hide_log_buttons,
logc=logc,
mask_cmap=mask_cmap,
mask_color=mask_color,
Expand Down
4 changes: 4 additions & 0 deletions src/plopp/plotting/_mesh3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def mesh3d(
cmin: sc.Variable | float = None,
edgecolor: str | None = None,
figsize: tuple[int, int] = (600, 400),
hide_log_buttons: bool = False,
logc: bool | None = None,
nan_color: str | None = None,
norm: Literal['linear', 'log'] | None = None,
Expand Down Expand Up @@ -90,6 +91,8 @@ def mesh3d(
The color of the edges. If None, no edges are drawn.
figsize:
The size of the 3d rendering area, in pixels: ``(width, height)``.
hide_log_buttons:
If ``True``, the interactive log buttons will be hidden.
logc:
Set to ``True`` for a logarithmic colorscale (only applicable if ``cbar`` is
``True``).
Expand Down Expand Up @@ -128,6 +131,7 @@ def mesh3d(
cmap=cmap,
edgecolor=edgecolor,
figsize=figsize,
hide_log_buttons=hide_log_buttons,
logc=logc,
nan_color=nan_color,
norm=norm,
Expand Down
4 changes: 4 additions & 0 deletions src/plopp/plotting/_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def plot(
grid: bool = False,
ignore_size: bool = False,
legend: bool | tuple[float, float] = True,
hide_log_buttons: bool = False,
logc: bool | None = None,
logx: bool | None = None,
logy: bool | None = None,
Expand Down Expand Up @@ -80,6 +81,8 @@ def plot(
The width and height of the figure, in inches.
grid:
Show grid if ``True``.
hide_log_buttons:
If ``True``, the interactive log buttons will be hidden.
ignore_size:
If ``True``, skip the check that prevents the rendering of very large data.
legend:
Expand Down Expand Up @@ -144,6 +147,7 @@ def plot(
errorbars=errorbars,
figsize=figsize,
grid=grid,
hide_log_buttons=hide_log_buttons,
legend=legend,
logc=logc,
logx=logx,
Expand Down
4 changes: 4 additions & 0 deletions src/plopp/plotting/_scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def scatter(
cmin: sc.Variable | float | None = None,
figsize: tuple[float, float] | None = None,
grid: bool = False,
hide_log_buttons: bool = False,
ignore_size: bool = False,
legend: bool | tuple[float, float] = True,
logc: bool | None = None,
Expand Down Expand Up @@ -126,6 +127,8 @@ def scatter(
If ``True``, use logarithmic scale for y-axis.
mask_color:
Color of markers for masked data.
hide_log_buttons:
If ``True``, the interactive log buttons will be hidden.
nan_color:
Color to use for NaN values in color mapping (only applicable if ``cbar`` is
``True``).
Expand Down Expand Up @@ -182,6 +185,7 @@ def scatter(
logx=logx,
logy=logy,
mask_color=mask_color,
hide_log_buttons=hide_log_buttons,
nan_color=nan_color,
norm=norm,
scale=scale,
Expand Down
4 changes: 4 additions & 0 deletions src/plopp/plotting/_scatter3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def scatter3d(
cmax: sc.Variable | float = None,
cmin: sc.Variable | float = None,
figsize: tuple[int, int] = (600, 400),
hide_log_buttons: bool = False,
logc: bool | None = None,
nan_color: str | None = None,
norm: Literal['linear', 'log'] | None = None,
Expand Down Expand Up @@ -117,6 +118,8 @@ def scatter3d(
perspective:
Set to ``True`` for a perspective camera. ``False`` will give an orthographic
(flat) camera.
hide_log_buttons:
If ``True``, the interactive log buttons will be hidden.
title:
The figure title.
vmin:
Expand Down Expand Up @@ -161,6 +164,7 @@ def scatter3d(
nan_color=nan_color,
norm=norm,
opacity=opacity,
hide_log_buttons=hide_log_buttons,
perspective=perspective,
title=title,
vmax=vmax,
Expand Down
4 changes: 4 additions & 0 deletions src/plopp/plotting/_slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def slicer(
errorbars: Literal['band', 'bar', True, False] = True,
figsize: tuple[float, float] | None = None,
grid: bool = False,
hide_log_buttons: bool = False,
legend: bool | tuple[float, float] = True,
logc: bool | None = None,
logx: bool | None = None,
Expand Down Expand Up @@ -322,6 +323,8 @@ def slicer(
The width and height of the figure, in inches.
grid:
Show grid if ``True``.
hide_log_buttons:
If ``True``, the interactive log buttons will be hidden.
legend:
Show legend if ``True``. If ``legend`` is a tuple, it should contain the
``(x, y)`` coordinates of the legend's anchor point in axes coordinates.
Expand Down Expand Up @@ -391,6 +394,7 @@ def slicer(
errorbars=errorbars,
figsize=figsize,
grid=grid,
hide_log_buttons=hide_log_buttons,
legend=legend,
logc=logc,
logx=logx,
Expand Down
4 changes: 4 additions & 0 deletions src/plopp/plotting/_superplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def superplot(
errorbars: Literal['band', 'bar', True, False] = True,
figsize: tuple[float, float] | None = None,
grid: bool = False,
hide_log_buttons: bool = False,
legend: bool | tuple[float, float] = True,
logx: bool | None = None,
logy: bool | None = None,
Expand Down Expand Up @@ -68,6 +69,8 @@ def superplot(
The width and height of the figure, in inches.
grid:
Show grid if ``True``.
hide_log_buttons:
If ``True``, the interactive log buttons will be hidden.
legend:
Show legend if ``True``. If ``legend`` is a tuple, it should contain the
``(x, y)`` coordinates of the legend's anchor point in axes coordinates.
Expand Down Expand Up @@ -124,6 +127,7 @@ def superplot(
legend=legend,
logx=logx,
logy=logy,
hide_log_buttons=hide_log_buttons,
mask_color=mask_color,
norm=norm,
scale=scale,
Expand Down
4 changes: 4 additions & 0 deletions src/plopp/plotting/_xyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def xyplot(
errorbars: Literal['band', 'bar', True, False] = True,
figsize: tuple[float, float] | None = None,
grid: bool = False,
hide_log_buttons: bool = False,
legend: bool | tuple[float, float] = True,
logx: bool | None = None,
logy: bool | None = None,
Expand Down Expand Up @@ -84,6 +85,8 @@ def xyplot(
The width and height of the figure, in inches.
grid:
Show grid if ``True``.
hide_log_buttons:
If ``True``, the interactive log buttons will be hidden.
legend:
Show legend if ``True``. If ``legend`` is a tuple, it should contain the
``(x, y)`` coordinates of the legend's anchor point in axes coordinates.
Expand Down Expand Up @@ -127,6 +130,7 @@ def xyplot(
errorbars=errorbars,
figsize=figsize,
grid=grid,
hide_log_buttons=hide_log_buttons,
legend=legend,
logx=logx,
logy=logy,
Expand Down
Loading
Loading