Skip to content

Commit

Permalink
CurveFits.plotReplicates no longer fails if too many replicates (#52)
Browse files Browse the repository at this point in the history
Instead recycles colors and markers.
To make these combinations unique by default,
also added another marker to `CBMARKERS`.
  • Loading branch information
jbloom authored Jan 1, 2024
1 parent 77434b9 commit b386b81
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file.

The format is based on `Keep a Changelog <https://keepachangelog.com>`_.

1.1.2
-----

Fixed
+++++
- ``CurveFits.plotReplicates`` no longer fails if too many replicates, but instead recycles colors and markers. To make these combinations unique by default, also added another marker to ``CBMARKERS``.

1.1.1
-----

Expand Down
2 changes: 1 addition & 1 deletion neutcurve/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

__author__ = "Jesse Bloom"
__email__ = "[email protected]"
__version__ = "1.1.1"
__version__ = "1.1.2"
__url__ = "https://github.com/jbloomlab/neutcurve"

from neutcurve.curvefits import CurveFits # noqa: F401
Expand Down
5 changes: 2 additions & 3 deletions neutcurve/colorschemes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@
"#CC79A7",
)

#: list of matplotlib markers same length as `CBPALETTE`, from
#: list of matplotlib markers, from
#: https://matplotlib.org/api/markers_api.html
CBMARKERS = ("o", "^", "s", "D", "v", "<", ">", "p")
assert len(CBPALETTE) == len(CBBPALETTE) == len(CBMARKERS)
CBMARKERS = ("o", "^", "s", "D", "v", "<", ">", "p", "x")

if __name__ == "__main__":
import doctest
Expand Down
14 changes: 2 additions & 12 deletions neutcurve/curvefits.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,10 +1094,8 @@ def plotReplicates(
sera, viruses = self._sera_viruses_lists(sera, viruses)

# get replicates and make sure there aren't too many
nplottable = max(len(colors), len(markers))
if average_only:
replicates = ["average"]
nreplicates = 1
elif attempt_shared_legend:
replicates = collections.OrderedDict()
if show_average:
Expand All @@ -1108,7 +1106,6 @@ def plotReplicates(
if replicate != "average":
replicates[replicate] = True
replicates = list(collections.OrderedDict(replicates).keys())
nreplicates = len(replicates)
else:
replicates_by_serum_virus = collections.defaultdict(list)
for serum, virus in itertools.product(sera, viruses):
Expand All @@ -1120,13 +1117,6 @@ def plotReplicates(
for replicate in self.replicates[(serum, virus)]:
if replicate != "average":
replicates_by_serum_virus[key].append(replicate)
nreplicates = max(len(reps) for reps in replicates_by_serum_virus.values())
if nreplicates > nplottable:
raise ValueError(
f"Too many unique replicates. There are {nreplicates} on a single plot "
f"but only {nplottable} `colors` or `markers`. Either specify more "
"colors/markers, or try setting `attempt_shared_legend=False`"
)

# build list of plots appropriate for `plotGrid`
plotlist = []
Expand All @@ -1147,8 +1137,8 @@ def plotReplicates(
"virus": virus,
"replicate": replicate,
"label": {False: replicate, True: None}[average_only],
"color": colors[i],
"marker": markers[i],
"color": colors[i % len(colors)],
"marker": markers[i % len(markers)],
}
)
if curvelist:
Expand Down

0 comments on commit b386b81

Please sign in to comment.