Circosplot: Add legend indicating the label and color of each group of nodes
See original GitHub issue- nxviz version:
- Python version:
- Operating System:
Description
I worked with this library for a project that I had. One of the things that I used and that may be of benefit for other users of the library is to add to a circosplot the legend with labels and color for each group of the nodes. Attached the code below of how to do this and that you @ericmjl may like to incorporate to the library.
What I Did
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from matplotlib.colors import to_hex
# Get the label and color for each group used by nxviz
seen = set()
colors_group = [x for x in c.node_colors if not (x in seen or seen.add(x))] #Gets colors in RGBA
labels_group = sorted(list(set([c.graph.node[n][c.node_color] for n in c.nodes]))) #Gets group labels
# Create patchList to use as handle for plt.legend()
patchList = []
for color, label in zip(colors_group, labels_group):
color = to_hex(color, keep_alpha=True) #Convert RGBA to HEX value
data_key = mpatches.Patch(color=color, label=label)
patchList.append(data_key)
# Set the labels with the custom patchList
plt.legend(handles=patchList,
loc="lower center",
title="Enterprise size",
ncol=4, # 4 columns to spread the legends
borderpad=1,
bbox_to_anchor =(0.5, -0.05), # To move the legend box lower than the graph
shadow=True,
fancybox=True)
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
How can we mark legend for a scatter plot based on color
I want to add a legend to the graph such that the user understands that this particular color points corresponds to this particular...
Read more >API Documentation — nxviz 0.3 documentation - Read the Docs
group_label_position – Boolean, whether the group labels should be the same color as the nodes. node_color ( dict_key (often str )) – The...
Read more >How to manually add a legend with a color box on a Matplotlib ...
To create a legend with a color box, patches are used provided by the matplotlib.patches module. A patch nothing but a 2D artist...
Read more >mixOmics.pdf - Bioconductor
Title Omics Data Integration Project ... but we set it as a factor to set up the colors. ... Factor indicating the group...
Read more >Chapter 8 Flow | R Gallery Book - Bookdown
A Chord diagram allows to study flows between a set of entities. Entities (nodes) are displayed all around a circle and connected with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Since the feature has been added, I am going to close this issue
Hello @ericmjl
Code added:
Included dummy examples in the directory "examples\circos"for: