-
Notifications
You must be signed in to change notification settings - Fork 0
Pin Colors Dimensionality Reduction Plot #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
Need changes from header of scatterplot
…of header keyword argument
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
}
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: