[Tutor] optimize a plot
lina
lina.lastname at gmail.com
Wed Nov 16 09:03:00 CET 2011
On Wed, Nov 16, 2011 at 1:51 AM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> On 15/11/11 14:34, lina wrote:
>>
>> Sorry for some not mature questions asked before, fixed now by:
>>
>> def PlotPathway(list1):
>>
>> for i in range(len(list1)):
>> for j in range(len(list1[i])-1):
>> if list1[i][j] != list1[i][j+1]:
>> if ((int(list1[i][j]))< 43 and
>> (int(list1[i][j-1]))< 43):
>> g.add_edge(list1[i][j], list1[i][j+1])
>> for i in range(43,84):
>> if g.has_node(i):
>> g.delete_node(i)
>> g.draw('graph4.png', prog="dot")
>>
>>
>> just still don't get why the "if" does not work as expected.
>
>
> Sorry, I haven't been following you earlier thread.
My mistake, I attached a figure in earlier posting,
but the message was held for approval due to it's too big.
I just noticed those three notifications, so I canceled posting, not
sure waiting for approval will get approved or not.
> Which 'if'? There are 3 to choose from.
> And how did you expect it to behave, and what is it doing that you didn't
> expect?
During those process, I met lots of problems, some are fixed, and some
are forgot or switch to another problem.
One thing is that I did not know how to get node value,
and for the node value to change the attirbute of this certain node.
This way is wrong:
def PlotPathway(list1):
for i in range(len(list1)):
for j in range(len(list1[i])-1):
if list1[i][j] != list1[i][j+1]:
g.add_edge(list1[i][j], list1[i][j+1])
if list1[i][j]<=42:
g.node_attr.update(color='deepskyblue',style='filled')
if list1[i][j] > 42:
g.node_attr.update(color='green',style='filled')
it will keep on updating and mess things up, but this way can get the value.
Below is a better way:
def colorNodes(listofnodes):
node_list=[]
node_list_A=[]
node_list_B=[]
for node in g:
node_list.append(node)
if node.value < 42: ### I don't know how to get the value of the node.
g.node_attr.update(color='deepskyblue',style='filled')
else:
g.node_attr.update(color='green',style='filled')
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list