Skip to content
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

Backfill labeled node with color #30

Open
CJ-Wright opened this issue Jun 28, 2018 · 7 comments
Open

Backfill labeled node with color #30

CJ-Wright opened this issue Jun 28, 2018 · 7 comments

Comments

@CJ-Wright
Copy link
Contributor

Is it possible to backfill a labeled node with a color? If so, how?

@dschult
Copy link
Member

dschult commented Jun 30, 2018

What do you mean by backfill?
You can fill a node and you can set textcolor and background color on text

@CJ-Wright
Copy link
Contributor Author

I mean background color. However that doesn't seem to be possible.

import networkx as nx
import matplotlib.pyplot as plt
import random
from grave import plot_network


graph = nx.barbell_graph(10, 14)

nx.set_node_attributes(graph, dict(graph.degree()), 'degree')
graph = nx.relabel_nodes(graph, {k: str(i) for i, k in enumerate(graph.node)})


def degree_colorer(node_attributes):
    deg = node_attributes['degree']
    shape = random.choice(['s', 'o', '^', 'v', '8'])
    if deg > 5:
        return {'color': 'r', 'size': 20*deg,
                # 'shape': shape,
                'label': 'hi'
                }
    return {'color': 'b', 'size': 20*deg,
            # 'shape': shape,
            'label': 'hi'
            }


def pathological_edge_style(edge_attrs):
    return {'color': random.choice(['r', (0, 1, 0, .5), 'xkcd:ocean'])}


fig, ax = plt.subplots()
plot_network(graph, ax=ax,
             node_style=dict(node_size=20, color='r', edgecolor='r'),
             # node_style=degree_colorer,
             edge_style=pathological_edge_style,
             node_label_style={'font_size': 20,
                               'font_color': 'r',
                               'backgroundcolor': 'b'
                               }
)
plt.show()

'''
We can calculate the execution order by walking the graph from a node and
summing it's edge labels (with zeros if there is none). This way all the nodes
on the first path will have a value of zero. Finally, since some nodes are
part of multiple trr
'''

Is the backgroundcolor key being passed in?

@dschult
Copy link
Member

dschult commented Jul 2, 2018

You are correct -- while that property (and others) are available in matplotlib, the GraVE code doesn't pass through many text attributes to the label artists.

Is there a reason we limit the attributes using key_map here?
Is there a nice way to have key_map mimic the matplotlib attributes directly?

@CJ-Wright
Copy link
Contributor Author

CJ-Wright commented Jul 2, 2018

FYI I also hacked the Text object created (to make all the nodes red) and still no joy.

@dschult
Copy link
Member

dschult commented Jul 2, 2018

Ahh -- in your example, the text is so large that it covers up the nodes. You have set the node_size to 20 but that doesn't seem to do anything. A little hunting shows t hat you need to set size=20 for nodes rather than node_size .

Looks like we have to make styles better at catching buggy input!

Anyway, if you use size=2000 you will see red disk nodes around your text labels.

@CJ-Wright
Copy link
Contributor Author

Yey human fuzzing!

@CJ-Wright
Copy link
Contributor Author

As a follow up on this I was able to change the node size and see the color but the text background color seems to be white, is it possible to change this?

figure_1-24

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

No branches or pull requests

2 participants