Skip to content

Commit

Permalink
Generate a default ID if not explicitly specified
Browse files Browse the repository at this point in the history
  • Loading branch information
eltos committed Jan 24, 2025
1 parent e488306 commit 876890e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
6 changes: 5 additions & 1 deletion xplt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import re
import types
import uuid

import matplotlib as mpl
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -879,9 +880,12 @@ def _create_artists(self, callback, dataset_id=None):
Signature: (i, j, k, axis, p) -> artist
Where i, j, k are the subplot, twin-axis, trace indices respectively;
axis is the axis and the string p is the property to plot.
dataset_id (str | None): The dataset identifier if this plot represents multiple datasets
dataset_id (str | None): The dataset identifier if this plot represents multiple datasets.
If None, and a default dataset already exists, a new UUID is generated.
"""

if dataset_id is None and None in self._artists:
dataset_id = str(uuid.uuid4())
if dataset_id in self._artists:
raise ValueError(f"Dataset identifier `{dataset_id}` already exists")
if dataset_id is not None and not isinstance(dataset_id, str):
Expand Down
8 changes: 4 additions & 4 deletions xplt/particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ def __init__(
if add_default_dataset:
self.add_dataset(None, particles=particles, mask=mask, plot_kwargs=plot_kwargs)

def add_dataset(self, id, *, plot_kwargs=None, **kwargs):
def add_dataset(self, id=None, *, plot_kwargs=None, **kwargs):
"""Create artists for a new dataset to the plot and optionally update their values
Args:
id (str): An arbitrary dataset identifier unique for this plot
id (str): An arbitrary dataset identifier unique for this plot. Defaults to a randomly generated UUID.
plot_kwargs (dict): Keyword arguments passed to the plot function, see :meth:`matplotlib.axes.Axes.plot`.
**kwargs: Arguments passed to :meth:`~.particles.ParticleHistogramPlot.update`.
"""
Expand Down Expand Up @@ -489,11 +489,11 @@ def __init__(
if add_default_dataset:
self.add_dataset(None, particles=particles, mask=mask, plot_kwargs=plot_kwargs)

def add_dataset(self, id, *, plot_kwargs=None, **kwargs):
def add_dataset(self, id=None, *, plot_kwargs=None, **kwargs):
"""Create artists for a new dataset to the plot and optionally update their values
Args:
id (str): An arbitrary dataset identifier unique for this plot
id (str): An arbitrary dataset identifier unique for this plot. Defaults to a randomly generated UUID.
plot_kwargs (dict): Keyword arguments passed to the plot function, see :meth:`matplotlib.axes.Axes.plot`.
**kwargs: Arguments passed to :meth:`~.particles.ParticleHistogramPlot.update`.
"""
Expand Down
24 changes: 15 additions & 9 deletions xplt/timestructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,9 @@ def bin_time(self):
"""Time bin width in s"""
return self.bin_width

def add_dataset(self, id, *, plot_kwargs=None, particles=None, timeseries=None, **kwargs):
def add_dataset(
self, id=None, *, plot_kwargs=None, particles=None, timeseries=None, **kwargs
):
"""Create artists for a new dataset to the plot and optionally update their values
See :meth:`~.particles.ParticleHistogramPlot.add_dataset`.
Expand Down Expand Up @@ -616,7 +618,7 @@ def __init__(

def add_dataset(
self,
id,
id=None,
*,
plot_kwargs=None,
averaging_shadow=True,
Expand All @@ -626,7 +628,7 @@ def add_dataset(
"""Create artists for a new dataset to the plot and optionally update their values
Args:
id (str): An arbitrary dataset identifier unique for this plot
id (str): An arbitrary dataset identifier unique for this plot. Defaults to a randomly generated UUID.
plot_kwargs (dict): Keyword arguments passed to the plot function, see :meth:`matplotlib.axes.Axes.plot`.
averaging_shadow (bool): Use this to en-/disable the shadow in case of averaging.
See averaging parameter of :class:`~.particles.ParticleHistogramPlot` constructor.
Expand Down Expand Up @@ -1010,11 +1012,13 @@ def __init__(
poisson_kwargs=poisson_kwargs,
)

def add_dataset(self, id, *, plot_kwargs=None, poisson=False, poisson_kwargs=None, **kwargs):
def add_dataset(
self, id=None, *, plot_kwargs=None, poisson=False, poisson_kwargs=None, **kwargs
):
"""Create artists for a new dataset to the plot and optionally update their values
Args:
id (str): An arbitrary dataset identifier unique for this plot
id (str): An arbitrary dataset identifier unique for this plot. Defaults to a randomly generated UUID.
plot_kwargs (dict): Keyword arguments passed to the plot function, see :meth:`matplotlib.axes.Axes.plot`.
poisson (bool): If true, indicate ideal poisson distribution.
poisson_kwargs (dict): Additional keyword arguments passed to the plot function for Poisson limit.
Expand Down Expand Up @@ -1234,11 +1238,13 @@ def __init__(
poisson_kwargs=poisson_kwargs,
)

def add_dataset(self, id, *, plot_kwargs=None, poisson=True, poisson_kwargs=None, **kwargs):
def add_dataset(
self, id=None, *, plot_kwargs=None, poisson=True, poisson_kwargs=None, **kwargs
):
"""Create artists for a new dataset to the plot and optionally update their values
Args:
id (str): An arbitrary dataset identifier unique for this plot
id (str): An arbitrary dataset identifier unique for this plot. Defaults to a randomly generated UUID.
plot_kwargs (dict): Keyword arguments passed to the plot function, see :meth:`matplotlib.axes.Axes.plot`.
poisson (bool): If true, indicate ideal poisson distribution.
poisson_kwargs (dict): Additional keyword arguments passed to the plot function for Poisson limit.
Expand Down Expand Up @@ -1467,7 +1473,7 @@ def __init__(

def add_dataset(
self,
id,
id=None,
*,
plot_kwargs=None,
std=True,
Expand All @@ -1479,7 +1485,7 @@ def add_dataset(
"""Create artists for a new dataset to the plot and optionally update their values
Args:
id (str): An arbitrary dataset identifier unique for this plot
id (str): An arbitrary dataset identifier unique for this plot. Defaults to a randomly generated UUID.
plot_kwargs (dict): Keyword arguments passed to the plot function, see :meth:`matplotlib.axes.Axes.plot`.
std (bool): Whether or not to plot standard deviation of variability as errorbar.
Only relevant if counting_bins_per_evaluation is not None.
Expand Down

0 comments on commit 876890e

Please sign in to comment.