Skip to content

Commit

Permalink
copy changes from PR#232
Browse files Browse the repository at this point in the history
  • Loading branch information
nvaytet committed Aug 7, 2023
1 parent d5f7537 commit fb5bec2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/plopp/backends/matplotlib/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class Canvas:
The aspect ratio for the axes.
cbar:
Add axes to host a colorbar if ``True``.
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.
"""

def __init__(
Expand All @@ -68,6 +71,7 @@ def __init__(
autoscale: Literal['auto', 'grow'] = 'auto',
aspect: Literal['auto', 'equal'] = 'auto',
cbar: bool = False,
legend: Union[bool, Tuple[float, float]] = True,
**ignored,
):
# Note on the `**ignored`` keyword arguments: the figure which owns the canvas
Expand All @@ -88,6 +92,7 @@ def __init__(
self.dims = {}
self._own_axes = False
self._autoscale = autoscale
self._legend = legend

if self.ax is None:
self._own_axes = True
Expand Down
7 changes: 5 additions & 2 deletions src/plopp/backends/matplotlib/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,11 @@ def _make_line(
fmt="none",
)

if self.label:
self._ax.legend()
if self.label and self._canvas._legend:
leg_args = {}
if isinstance(self._canvas._legend, (list, tuple)):
leg_args = {'loc': self._canvas._legend}
self._ax.legend(**leg_args)

def _make_data(self) -> dict:
x = self._data.meta[self._dim]
Expand Down
5 changes: 5 additions & 0 deletions src/plopp/graphics/lineview.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class LineView(View):
Format of the figure displayed in the Jupyter notebook. If ``None``, a SVG is
created as long as the number of markers in the figure is not too large. If too
many markers are drawn, a PNG image is created instead.
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.
**kwargs:
All other kwargs are forwarded to Matplotlib:
Expand All @@ -80,6 +83,7 @@ def __init__(
title: Optional[str] = None,
figsize: Tuple[float, float] = None,
format: Optional[Literal['svg', 'png']] = None,
legend: Union[bool, Tuple[float, float]] = True,
**kwargs
):
super().__init__(*nodes)
Expand All @@ -98,6 +102,7 @@ def __init__(
vmin=vmin,
vmax=vmax,
autoscale=autoscale,
legend=legend,
**kwargs
)
self.canvas.yscale = norm
Expand Down
5 changes: 5 additions & 0 deletions src/plopp/plotting/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def plot(
vmin: Optional[Union[Variable, int, float]] = None,
vmax: Optional[Union[Variable, int, float]] = None,
autoscale: Literal['auto', 'grow'] = 'auto',
legend: Union[bool, Tuple[float, float]] = True,
**kwargs,
):
"""Plot a Scipp object.
Expand Down Expand Up @@ -78,6 +79,9 @@ def plot(
The behavior of the axis (1d plots) or the color range limits (2d plots).
If ``auto``, the limits automatically adjusts every time the data changes.
If ``grow``, the limits are allowed to grow with time but they do not shrink.
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.
**kwargs:
All other kwargs are directly forwarded to Matplotlib, the underlying plotting
library. The underlying functions called are the following:
Expand All @@ -102,6 +106,7 @@ def plot(
'vmax': vmax,
'autoscale': autoscale,
'figsize': figsize,
'legend': legend,
**kwargs,
}

Expand Down

0 comments on commit fb5bec2

Please sign in to comment.