Skip to content

Commit 798fa3e

Browse files
committed
fix: allow line_color to be fixed if passed to plot for line plots
1 parent 9482c70 commit 798fa3e

4 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎pyopenms_viz/_bokeh/core.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def plot(cls, fig, data, x, y, by: str | None = None, plot_3d=False, **kwargs):
219219
if by is None:
220220
source = ColumnDataSource(data)
221221
if color_gen is not None:
222-
kwargs["line_color"] = next(color_gen)
222+
kwargs["line_color"] = color_gen if isinstance(color_gen, str) else next(color_gen)
223223
line = fig.line(x=x, y=y, source=source, **kwargs)
224224

225225
return fig, None
@@ -229,7 +229,7 @@ def plot(cls, fig, data, x, y, by: str | None = None, plot_3d=False, **kwargs):
229229
for group, df in data.groupby(by):
230230
source = ColumnDataSource(df)
231231
if color_gen is not None:
232-
kwargs["line_color"] = next(color_gen)
232+
kwargs["line_color"] = color_gen if isinstance(color_gen, str) else next(color_gen)
233233
line = fig.line(x=x, y=y, source=source, **kwargs)
234234
legend_items.append((group, [line]))
235235

‎pyopenms_viz/_core.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,11 @@ def plot(self, data, x, y, **kwargs):
495495
"""
496496
Create the plot
497497
"""
498-
color_gen = ColorGenerator()
498+
if 'line_color' not in kwargs:
499+
color_gen = ColorGenerator()
500+
else:
501+
color_gen = kwargs['line_color']
502+
499503
tooltip_entries = {"retention time": x, "intensity": y}
500504
if "Annotation" in self.data.columns:
501505
tooltip_entries["annotation"] = "Annotation"

‎pyopenms_viz/_matplotlib/core.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ def plot( # type: ignore[override]
204204
legend_labels = []
205205

206206
if by is None:
207-
(line,) = ax.plot(data[x], data[y], color=next(color_gen))
207+
(line,) = ax.plot(data[x], data[y], color=color_gen if isinstance(color_gen, str) else next(color_gen))
208208

209209
return ax, None
210210
else:
211211
for group, df in data.groupby(by):
212-
(line,) = ax.plot(df[x], df[y], color=next(color_gen))
212+
(line,) = ax.plot(df[x], df[y], color=color_gen if isinstance(color_gen, str) else next(color_gen))
213213
legend_lines.append(line)
214214
legend_labels.append(group)
215215
return ax, (legend_lines, legend_labels)

‎pyopenms_viz/_plotly/core.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def plot( # type: ignore[override]
221221
traces = []
222222
if by is None:
223223
trace = go.Scatter(
224-
x=data[x], y=data[y], mode="lines", line=dict(color=next(color_gen))
224+
x=data[x], y=data[y], mode="lines", line=dict(color=color_gen if isinstance(color_gen, str) else next(color_gen))
225225
)
226226
traces.append(trace)
227227
else:
@@ -231,7 +231,7 @@ def plot( # type: ignore[override]
231231
y=df[y],
232232
mode="lines",
233233
name=group,
234-
line=dict(color=next(color_gen)),
234+
line=dict(color=color_gen if isinstance(color_gen, str) else next(color_gen)),
235235
)
236236
traces.append(trace)
237237

0 commit comments

Comments
 (0)