question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
walter-hernandezcommented, Mar 4, 2020

Since the feature has been added, I am going to close this issue

0reactions
walter-hernandezcommented, Mar 2, 2020

Hello @ericmjl

Code added:

  • Added the argument “group_legend” for the user to indicate if it wants the graph to include the legend or not.
  • Exposed the legend_handles in the case that the user wants to customized the legend

Included dummy examples in the directory "examples\circos"for:

  • The default legend:

circusplot_defaultlegend

  • How to customize the legend using the CircosPlot().legend_handles

circusplot_customlegend

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found