Ich versuche, ein colorbar
mein networkx
gezogen matplotlib ax
aus dem Bereich von 1
(das ist der leichteste) und 3
(das ist die dunkelste) hinzufügen [Besuche die Linie w/cmap
unten]. Ich versuche, viele PyData
Funktionalitäten zu kombinieren.Wie fügt man `colorbar` zu` networkx` mit einer `seaborn` Farbpalette hinzu? (Python 3)
Wie kann ich ein Farbbalken-Feature in einem Netzwerkexplot mit einer Seaborn-Farbpalette hinzufügen?
# Set up Graph
DF_adj = pd.DataFrame(np.array(
[[1, 0, 1, 1],
[0, 1, 1, 0],
[1, 1, 1, 1],
[1, 0, 1, 1] ]), columns=['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)'], index=['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)'])
G = nx.Graph(DF_adj.as_matrix())
G = nx.relabel_nodes(G, dict(zip(range(4), ['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)'])))
# Color mapping
color_palette = sns.cubehelix_palette(3)
cmap = {k:color_palette[v-1] for k,v in zip(['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)'],[2, 1, 3, 2])}
# Draw
nx.draw(G, node_color=[cmap[node] for node in G.nodes()], with_labels=True)
Dabei sind sie alle mit matplotlib
Farbpaletten: arbeiten http://jakevdp.github.io/mpl_tutorial/tutorial_pages/tut3.html Ich habe sogar versucht, sie zu einem ListedColormap
Objekt konvertieren, aber es hat nicht.
Dies gilt nicht für meine Situation arbeiten entweder b/c matplotlib colormap: Seaborn regplot with colorbar?
Das Gleiche gilt für http://matplotlib.org/examples/pylab_examples/colorbar_tick_labelling_demo.html
war dies der nächste, die ich bekam, aber es hat ich eine automatische Skalierung Nonetype nicht funktioniert habe: How do I use seaborns color_palette as a colormap in matplotlib?
Does not 'nx.draw' Rückkehr die Künstler kreiert? – tacaswell
'nx.draw' gibt nichts zurück (zumindest nicht in diesem Fall), weshalb ich mit meiner Antwort gegangen bin. – lanery