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
6 changes: 2 additions & 4 deletions src/plopp/backends/matplotlib/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
import scipp as sc
from matplotlib.axes import Axes
from matplotlib.dates import date2num
from matplotlib.lines import Line2D

from ...graphics.bbox import BoundingBox
from ..common import check_ndim, make_line_bbox, make_line_data
from .canvas import Canvas
from .utils import parse_dicts_in_kwargs
from .utils import default_marker, parse_dicts_in_kwargs


def _to_float(x):
Expand Down Expand Up @@ -255,11 +254,10 @@ def __init__(
'color': f'C{artist_number}',
'zorder': 2,
}
markers = list(Line2D.markers.keys())
default_plot_style = {
'linestyle': 'none',
'linewidth': 1.5,
'marker': markers[(artist_number + 2) % len(markers)],
'marker': default_marker(artist_number),
'color': f'C{artist_number}',
'zorder': 2,
}
Expand Down
6 changes: 2 additions & 4 deletions src/plopp/backends/matplotlib/scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@

import numpy as np
import scipp as sc
from matplotlib.lines import Line2D

from ...core.utils import merge_masks
from ...graphics.bbox import BoundingBox, axis_bounds
from ...graphics.colormapper import ColorMapper
from ..common import check_ndim
from .canvas import Canvas
from .utils import parse_dicts_in_kwargs
from .utils import default_marker, parse_dicts_in_kwargs


class Scatter:
Expand Down Expand Up @@ -79,9 +78,8 @@ def __init__(
self._unit = self._data.unit
self._id = uuid.uuid4().hex

markers = list(Line2D.markers.keys())
default_plot_style = {
'marker': markers[(artist_number + 2) % len(markers)],
'marker': default_marker(artist_number),
}
if not cbar:
default_plot_style['color'] = f'C{artist_number}'
Expand Down
13 changes: 13 additions & 0 deletions src/plopp/backends/matplotlib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D


def fig_to_bytes(fig: plt.Figure, form: Literal['png', 'svg'] = 'png') -> bytes:
Expand Down Expand Up @@ -72,6 +73,18 @@ def make_figure(*args, **kwargs) -> plt.Figure:
return fig


def default_marker(artist_number: int) -> str:
"""
Return a marker from a cycle of markers, based on the artist number.

Only filled markers are used, as ``Line2D.markers`` also contains integer markers
and markers that draw nothing (e.g. ``'none'`` and ``''``).
"""
markers = Line2D.filled_markers
# Start the cycle at 'o' instead of the barely visible '.'.
return markers[(artist_number + 1) % len(markers)]


def make_legend(leg: bool | tuple[float, float] | str) -> dict:
"""
Create a dict of arguments to be used in the legend creation.
Expand Down
9 changes: 9 additions & 0 deletions tests/backends/matplotlib/mpl_line_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np
import pytest
import scipp as sc
from matplotlib.markers import MarkerStyle

from plopp.backends.matplotlib.canvas import Canvas
from plopp.backends.matplotlib.line import Line
Expand Down Expand Up @@ -183,6 +184,14 @@ def test_kwarg_marker():
assert line._line.get_marker() == '+'


def test_default_marker_is_visible_for_large_artist_number():
da = data_array(ndim=1)
canvas = Canvas()
for artist_number in range(50):
line = Line(canvas=canvas, data=da, artist_number=artist_number)
assert MarkerStyle(line.marker).is_filled()


@pytest.mark.parametrize("mode", ['band', 'bar', True])
def test_line_color_with_errorbars(mode):
from matplotlib.colors import to_hex
Expand Down
6 changes: 6 additions & 0 deletions tests/backends/matplotlib/mpl_plot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,9 @@ def test_aspect_ratio():
da = data_array(ndim=2)
fig = da.plot(aspect='equal')
assert fig.canvas.ax.get_aspect() == 1.0


def test_plot_many_lines():
da = data_array(ndim=1)
fig = pp.plot({str(i): da for i in range(50)})
assert len(fig.artists) == 50
Loading