networkX node colours wrong oder












0















I am trying to use the NetworkX library and I am having troubles getting my nodes to display the correct colour. Below is a simple example where I am using a colormap. From my understanding node 'B' should show up as red, but as you can see in the picture 'C' is red. Can someone please tell me what I am doing wrong? Many thanks.



import networkx as nx
import matplotlib
matplotlib.use("agg")
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches

failed_patch = mpatches.Patch(color='red', label='failed')
success_patch = mpatches.Patch(color='green', label='success')
plt.legend(handles=[success_patch,failed_patch])

G=nx.DiGraph()
nodes = ['A', 'B', 'C', 'D']
G.add_path(nodes)

color_map = ['forestgreen', 'red', 'forestgreen', 'forestgreen']
lpos = { 'A': (-0.008, 0), 'B': (-0.008, -5), 'C': (-0.008, -10),
'D': (-0.008, -15)}
pos = { 'A': (0, 0), 'B': (0, -5),'C': (0, -10),'D': (0, -15)}

nx.draw(G,node_size=1000,alpha=0.8,pos=pos,node_color=color_map,
node_shape='o',font_size=16, with_labels=True)

plt.savefig('diagram.png')


enter image description here










share|improve this question























  • not sure why your getting that result. your code on my machine produces Red for node B i.imgur.com/rkzZj5v.png, only change i made what matplotlib.use("TkAgg")

    – davedwards
    Nov 18 '18 at 6:42













  • I doubt the code you show here produces the graph that is shown, simply be cause there is no partial anywhere in the code. Make sure to show the actual output of your code.

    – ImportanceOfBeingErnest
    Nov 18 '18 at 11:21
















0















I am trying to use the NetworkX library and I am having troubles getting my nodes to display the correct colour. Below is a simple example where I am using a colormap. From my understanding node 'B' should show up as red, but as you can see in the picture 'C' is red. Can someone please tell me what I am doing wrong? Many thanks.



import networkx as nx
import matplotlib
matplotlib.use("agg")
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches

failed_patch = mpatches.Patch(color='red', label='failed')
success_patch = mpatches.Patch(color='green', label='success')
plt.legend(handles=[success_patch,failed_patch])

G=nx.DiGraph()
nodes = ['A', 'B', 'C', 'D']
G.add_path(nodes)

color_map = ['forestgreen', 'red', 'forestgreen', 'forestgreen']
lpos = { 'A': (-0.008, 0), 'B': (-0.008, -5), 'C': (-0.008, -10),
'D': (-0.008, -15)}
pos = { 'A': (0, 0), 'B': (0, -5),'C': (0, -10),'D': (0, -15)}

nx.draw(G,node_size=1000,alpha=0.8,pos=pos,node_color=color_map,
node_shape='o',font_size=16, with_labels=True)

plt.savefig('diagram.png')


enter image description here










share|improve this question























  • not sure why your getting that result. your code on my machine produces Red for node B i.imgur.com/rkzZj5v.png, only change i made what matplotlib.use("TkAgg")

    – davedwards
    Nov 18 '18 at 6:42













  • I doubt the code you show here produces the graph that is shown, simply be cause there is no partial anywhere in the code. Make sure to show the actual output of your code.

    – ImportanceOfBeingErnest
    Nov 18 '18 at 11:21














0












0








0








I am trying to use the NetworkX library and I am having troubles getting my nodes to display the correct colour. Below is a simple example where I am using a colormap. From my understanding node 'B' should show up as red, but as you can see in the picture 'C' is red. Can someone please tell me what I am doing wrong? Many thanks.



import networkx as nx
import matplotlib
matplotlib.use("agg")
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches

failed_patch = mpatches.Patch(color='red', label='failed')
success_patch = mpatches.Patch(color='green', label='success')
plt.legend(handles=[success_patch,failed_patch])

G=nx.DiGraph()
nodes = ['A', 'B', 'C', 'D']
G.add_path(nodes)

color_map = ['forestgreen', 'red', 'forestgreen', 'forestgreen']
lpos = { 'A': (-0.008, 0), 'B': (-0.008, -5), 'C': (-0.008, -10),
'D': (-0.008, -15)}
pos = { 'A': (0, 0), 'B': (0, -5),'C': (0, -10),'D': (0, -15)}

nx.draw(G,node_size=1000,alpha=0.8,pos=pos,node_color=color_map,
node_shape='o',font_size=16, with_labels=True)

plt.savefig('diagram.png')


enter image description here










share|improve this question














I am trying to use the NetworkX library and I am having troubles getting my nodes to display the correct colour. Below is a simple example where I am using a colormap. From my understanding node 'B' should show up as red, but as you can see in the picture 'C' is red. Can someone please tell me what I am doing wrong? Many thanks.



import networkx as nx
import matplotlib
matplotlib.use("agg")
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches

failed_patch = mpatches.Patch(color='red', label='failed')
success_patch = mpatches.Patch(color='green', label='success')
plt.legend(handles=[success_patch,failed_patch])

G=nx.DiGraph()
nodes = ['A', 'B', 'C', 'D']
G.add_path(nodes)

color_map = ['forestgreen', 'red', 'forestgreen', 'forestgreen']
lpos = { 'A': (-0.008, 0), 'B': (-0.008, -5), 'C': (-0.008, -10),
'D': (-0.008, -15)}
pos = { 'A': (0, 0), 'B': (0, -5),'C': (0, -10),'D': (0, -15)}

nx.draw(G,node_size=1000,alpha=0.8,pos=pos,node_color=color_map,
node_shape='o',font_size=16, with_labels=True)

plt.savefig('diagram.png')


enter image description here







python python-2.7 matplotlib networking






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 18 '18 at 5:27









user1768233user1768233

6811919




6811919













  • not sure why your getting that result. your code on my machine produces Red for node B i.imgur.com/rkzZj5v.png, only change i made what matplotlib.use("TkAgg")

    – davedwards
    Nov 18 '18 at 6:42













  • I doubt the code you show here produces the graph that is shown, simply be cause there is no partial anywhere in the code. Make sure to show the actual output of your code.

    – ImportanceOfBeingErnest
    Nov 18 '18 at 11:21



















  • not sure why your getting that result. your code on my machine produces Red for node B i.imgur.com/rkzZj5v.png, only change i made what matplotlib.use("TkAgg")

    – davedwards
    Nov 18 '18 at 6:42













  • I doubt the code you show here produces the graph that is shown, simply be cause there is no partial anywhere in the code. Make sure to show the actual output of your code.

    – ImportanceOfBeingErnest
    Nov 18 '18 at 11:21

















not sure why your getting that result. your code on my machine produces Red for node B i.imgur.com/rkzZj5v.png, only change i made what matplotlib.use("TkAgg")

– davedwards
Nov 18 '18 at 6:42







not sure why your getting that result. your code on my machine produces Red for node B i.imgur.com/rkzZj5v.png, only change i made what matplotlib.use("TkAgg")

– davedwards
Nov 18 '18 at 6:42















I doubt the code you show here produces the graph that is shown, simply be cause there is no partial anywhere in the code. Make sure to show the actual output of your code.

– ImportanceOfBeingErnest
Nov 18 '18 at 11:21





I doubt the code you show here produces the graph that is shown, simply be cause there is no partial anywhere in the code. Make sure to show the actual output of your code.

– ImportanceOfBeingErnest
Nov 18 '18 at 11:21












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53358164%2fnetworkx-node-colours-wrong-oder%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53358164%2fnetworkx-node-colours-wrong-oder%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini