Skip to content

Commit

Permalink
refactor: plotting for generalized scatter plot based on df
Browse files Browse the repository at this point in the history
  • Loading branch information
singjc committed Jun 2, 2024
1 parent b38a726 commit bb9715e
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions massdash/plotting/DebugPlotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,29 @@ class DebugPlotter:
def __init__(self):
self.fig = None

def plot(self, df):
def plot(self, df, x_col, y_col, title, x_axis_label, y_axis_label):
# Create a new plot
p = figure(title='Retention time transformation', x_axis_label='original RT [s]', y_axis_label='Delta RT [s]',
tools=['pan', 'wheel_zoom', 'box_zoom', 'reset', 'save'])
p = figure(title=title, x_axis_label=x_axis_label, y_axis_label=y_axis_label,
tools=['pan', 'wheel_zoom', 'box_zoom', 'reset', 'save'])

unique_filenames = df['filename'].unique()
colors = Category20[len(unique_filenames)]

legend_it = []
file_number = 1
for filename, grouped_df in df.groupby('filename'):

color = colors[file_number-1]
print(f"File {file_number}: {filename} | color: {color}")
color = colors[file_number - 1]
print(f"File {file_number}: {filename}")
# Add the scatter plot
source = ColumnDataSource(grouped_df)
renderer = p.scatter('experiment_rt', 'library_rt', source=source, size=10, alpha=0.5, color=color)
renderer = p.scatter(x_col, y_col, source=source, size=10, alpha=0.5, color=color)
legend_it.append((f"File {file_number}", [renderer]))
file_number += 1

# Configure the minimal hover tool
hover_minimal = HoverTool(tooltips=[
('original RT', '@experiment_rt{0.0}'),
('Delta RT', '@library_rt{0.0}'),
(x_axis_label, f'@{x_col}{{0.0}}'),
(y_axis_label, f'@{y_col}{{0.0}}'),
('Peptide Sequence', '@ModifiedPeptideSequence')
], name="Minimal Hover")
p.add_tools(hover_minimal)
Expand All @@ -57,7 +56,7 @@ def plot(self, df):

# Add a legend for the filename
legend = Legend(items=legend_it)
legend.click_policy="mute"
legend.click_policy = "mute"
legend.label_text_font_size = '8pt'
p.add_layout(legend, 'right')

Expand Down

0 comments on commit bb9715e

Please sign in to comment.