Open
Conversation
Need changes from header of scatterplot
…of header keyword argument
Ahmad8864
requested changes
Apr 22, 2025
src/spac/visualization.py
Outdated
| raise ValueError("x and y must have the same length.") | ||
| if labels is not None and len(labels) != len(x): | ||
| raise ValueError("Labels length should match x and y length.") | ||
| if color_map is not None: |
Collaborator
There was a problem hiding this comment.
Checking if color_map is None isn't needed, isinstance will correctly check if color_map is dict, even if color_map is None
src/spac/visualization.py
Outdated
| if color_map is not None: | ||
| if not isinstance(color_map, dict): | ||
| raise ValueError("`color_map` must be a dict mapping label→color.") | ||
| color_dict = color_map |
Collaborator
There was a problem hiding this comment.
This reassignment isn't needed, since you're just assigning it to cluster_to_color again down below. You can just set cluster_to_color = color_map online 146
src/spac/visualization.py
Outdated
| # Use the number of unique clusters to set the colormap length | ||
| cmap = ListedColormap(colors[:len(unique_clusters)]) | ||
| if color_map is not None: | ||
| cluster_to_color = color_dict |
Collaborator
There was a problem hiding this comment.
cluster_to_color = color_map
src/spac/visualization.py
Outdated
| cmap2 = plt.get_cmap('tab20b') | ||
| cmap3 = plt.get_cmap('tab20c') | ||
| colors = cmap1.colors + cmap2.colors + cmap3.colors | ||
| cluster_to_color = { |
Collaborator
There was a problem hiding this comment.
Removing the whole if statement and just doing this might be more concise:
cmap1 = plt.get_cmap('tab20')
cmap2 = plt.get_cmap('tab20b')
cmap3 = plt.get_cmap('tab20c')
colors = cmap1.colors + cmap2.colors + cmap3.colors
cluster_to_color = color_map if color_map is not None else {
str(cluster): colors[i % len(colors)]
for i, cluster in enumerate(unique_clusters)
}
Ahmad8864
approved these changes
Apr 29, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Updated dimensionality reduction plot to take in pin_colors keyword argument which allows users to pass in a string of a key located in ann-data uns. It then grabs the dictionary/color mapping and passes into 2dscatter function.
Changes: