Skip to content

Add ability to add taste names to plots - #38

Open
abuzarmahmood wants to merge 1 commit into
mainfrom
feature/add-taste-names-to-plots
Open

Add ability to add taste names to plots#38
abuzarmahmood wants to merge 1 commit into
mainfrom
feature/add-taste-names-to-plots

Conversation

@abuzarmahmood

Copy link
Copy Markdown
Member

Summary

This PR addresses issue #37 by adding the ability to specify custom taste names in all plotting functions.

Changes

Added an optional taste_names parameter to three main plotting functions:

  • generate_raster_plot()
  • generate_detailed_plot()
  • plot_env_pred_overlay()

Usage

Users can now pass a list of taste names to customize plot labels:

taste_names = ['Sucrose', 'NaCl', 'Citric Acid', 'Quinine']

# Raster plot with custom taste names
fig, ax = generate_raster_plot(
    segments_frame=segment_frame,
    taste_names=taste_names
)

# Detailed plot with custom taste names
fig, ax = generate_detailed_plot(
    segments_frame=segment_frame,
    raw_emg=env,
    trial_idx=0,
    taste_idx=0,
    taste_names=taste_names
)

# Overlay plot with custom taste names
fig, ax = plot_env_pred_overlay(
    segments_frame=segment_frame,
    raw_emg=env,
    taste_names=taste_names
)

Backward Compatibility

When taste_names is not provided (or is None), the functions default to the original behavior of displaying 'Taste 0', 'Taste 1', etc.

Testing

All functions maintain their original behavior when the parameter is not provided, ensuring backward compatibility with existing code.

Closes #37

Add optional taste_names parameter to all three main plotting functions:
- generate_raster_plot()
- generate_detailed_plot()
- plot_env_pred_overlay()

This allows users to specify custom taste names (e.g., 'Sucrose', 'NaCl')
instead of generic labels like 'Taste 0', 'Taste 1'.

Maintains backward compatibility by defaulting to 'Taste N' format when
taste_names is not provided.

Resolves #37

Co-authored-by: Ona <no-reply@ona.com>
@abuzarmahmood

Copy link
Copy Markdown
Member Author

Implementation Details

This solution adds a taste_names parameter to all three plotting functions in src/visualize.py:

Key Features:

  1. Optional Parameter: The taste_names parameter is optional and defaults to None
  2. Backward Compatible: When not provided, plots display the original 'Taste N' format
  3. Flexible: Accepts a list of strings corresponding to taste indices
  4. Consistent: Applied uniformly across all three plotting functions

Code Pattern:

The implementation follows a consistent pattern across all functions:

if taste_names is not None and taste < len(taste_names):
    taste_label = taste_names[taste]
else:
    taste_label = f'Taste {taste}'

This ensures that:

  • Custom names are used when provided
  • Falls back to default format if list is too short
  • Handles None gracefully
  • Maintains original behavior for existing code

Modified Functions:

  • generate_raster_plot() - Updates y-axis labels for each taste subplot
  • generate_detailed_plot() - Updates plot title with taste name
  • plot_env_pred_overlay() - Updates column headers in the grid plot

All docstrings have been updated to document the new parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to add taste names to plots

1 participant