Skip to content

Commit 7bf9423

Browse files
committed
Merge branch 'main' of github.com:OpenMS/pyopenms_viz
2 parents abe5fde + ab2e684 commit 7bf9423

File tree

9 files changed

+88307
-256
lines changed

9 files changed

+88307
-256
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The recommended way of installing pyopenms_viz is through the Python Package Ind
2222
First create a new environemnt:
2323

2424
```bash
25-
conda create --name=massdash python=3.10
25+
conda create --name=pyopenms_viz python=3.10
2626
conda activate pyopenms_viz
2727
```
2828
Then in the new environment install pyopenms_viz.

nbs/PeakMap.ipynb

+580-22
Large diffs are not rendered by default.

nbs/pyopenms_viz_tutorial.ipynb

+87,280-123
Large diffs are not rendered by default.

pyopenms_viz/_bokeh/core.py

+38-32
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class BOKEHLinePlot(BOKEHPlot, LinePlot):
210210

211211
@classmethod
212212
@APPEND_PLOT_DOC
213-
def plot(cls, fig, data, x, y, by: str | None = None, **kwargs):
213+
def plot(cls, fig, data, x, y, by: str | None = None, plot_3d=False, **kwargs):
214214
"""
215215
Plot a line plot
216216
"""
@@ -219,7 +219,7 @@ def plot(cls, fig, data, x, y, by: str | None = None, **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, **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

@@ -245,30 +245,17 @@ class BOKEHVLinePlot(BOKEHPlot, VLinePlot):
245245

246246
@classmethod
247247
@APPEND_PLOT_DOC
248-
def plot(cls, fig, data, x, y, by: str | None = None, **kwargs):
248+
def plot(cls, fig, data, x, y, by: str | None = None, plot_3d=False, **kwargs):
249249
"""
250250
Plot a set of vertical lines
251251
"""
252252
color_gen = kwargs.pop("line_color", None)
253253
if color_gen is None:
254254
color_gen = ColorGenerator()
255255
data["line_color"] = [next(color_gen) for _ in range(len(data))]
256-
if by is None:
257-
source = ColumnDataSource(data)
258-
line = fig.segment(
259-
x0=x,
260-
y0=0,
261-
x1=x,
262-
y1=y,
263-
source=source,
264-
line_color="line_color",
265-
**kwargs,
266-
)
267-
return fig, None
268-
else:
269-
legend_items = []
270-
for group, df in data.groupby(by):
271-
source = ColumnDataSource(df)
256+
if not plot_3d:
257+
if by is None:
258+
source = ColumnDataSource(data)
272259
line = fig.segment(
273260
x0=x,
274261
y0=0,
@@ -278,11 +265,27 @@ def plot(cls, fig, data, x, y, by: str | None = None, **kwargs):
278265
line_color="line_color",
279266
**kwargs,
280267
)
281-
legend_items.append((group, [line]))
282-
283-
legend = Legend(items=legend_items)
284-
285-
return fig, legend
268+
return fig, None
269+
else:
270+
legend_items = []
271+
for group, df in data.groupby(by):
272+
source = ColumnDataSource(df)
273+
line = fig.segment(
274+
x0=x,
275+
y0=0,
276+
x1=x,
277+
y1=y,
278+
source=source,
279+
line_color="line_color",
280+
**kwargs,
281+
)
282+
legend_items.append((group, [line]))
283+
284+
legend = Legend(items=legend_items)
285+
286+
return fig, legend
287+
else:
288+
raise NotImplementedError("3D Vline plots are not supported in Bokeh")
286289

287290
def _add_annotations(
288291
self,
@@ -312,7 +315,7 @@ class BOKEHScatterPlot(BOKEHPlot, ScatterPlot):
312315

313316
@classmethod
314317
@APPEND_PLOT_DOC
315-
def plot(cls, fig, data, x, y, by: str | None = None, **kwargs):
318+
def plot(cls, fig, data, x, y, by: str | None = None, plot_3d=False, **kwargs):
316319
"""
317320
Plot a scatter plot
318321
"""
@@ -466,16 +469,19 @@ class BOKEHPeakMapPlot(BOKEH_MSPlot, PeakMapPlot):
466469
"""
467470

468471
def create_main_plot(self, x, y, z, class_kwargs, other_kwargs):
469-
scatterPlot = self.get_scatter_renderer(self.data, x, y, **class_kwargs)
472+
if not self.plot_3d:
473+
scatterPlot = self.get_scatter_renderer(self.data, x, y, **class_kwargs)
470474

471-
self.fig = scatterPlot.generate(z=z, **other_kwargs)
475+
self.fig = scatterPlot.generate(z=z, **other_kwargs)
472476

473-
if self.annotation_data is not None:
474-
self._add_box_boundaries(self.annotation_data)
477+
if self.annotation_data is not None:
478+
self._add_box_boundaries(self.annotation_data)
475479

476-
tooltips, _ = self._create_tooltips({self.xlabel: x, self.ylabel: y, "intensity": z})
480+
tooltips, _ = self._create_tooltips({self.xlabel: x, self.ylabel: y, "intensity": z})
477481

478-
self._add_tooltips(self.fig, tooltips)
482+
self._add_tooltips(self.fig, tooltips)
483+
else:
484+
raise NotImplementedError("3D PeakMap plots are not supported in Bokeh")
479485

480486
def create_x_axis_plot(self, x, z, class_kwargs):
481487
x_fig = super().create_x_axis_plot(x, z, class_kwargs)

pyopenms_viz/_config.py

+4
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def default_legend_factory():
178178
title: str = "1D Plot"
179179
xlabel: str = "X-axis"
180180
ylabel: str = "Y-axis"
181+
zlabel: str = "Z-axis"
181182
x_axis_location: str = "below"
182183
y_axis_location: str = "left"
183184
min_border: str = 0
@@ -231,6 +232,7 @@ def set_plot_labels(self):
231232
"title": "PeakMap",
232233
"xlabel": "Retention Time",
233234
"ylabel": "mass-to-charge",
235+
"zlabel": "Intensity",
234236
},
235237
# Add more plot types as needed
236238
}
@@ -239,6 +241,8 @@ def set_plot_labels(self):
239241
self.title = plot_configs[self.kind]["title"]
240242
self.xlabel = plot_configs[self.kind]["xlabel"]
241243
self.ylabel = plot_configs[self.kind]["ylabel"]
244+
if self.kind == "peakmap":
245+
self.zlabel = plot_configs[self.kind]["zlabel"]
242246

243247
if self.relative_intensity and "Intensity" in self.ylabel:
244248
self.ylabel = "Relative " + self.ylabel

0 commit comments

Comments
 (0)