Okay, the bug is here: ["" if is_hashtag(vertex) else g.vs["name"] for vertex in g.vs]
You need vertex["name"] in place of g.vs["name"] -- right now you are querying the name of all the vertices if the current vertex contains a hashtag. It is easy to overlook. T. On 01/08, Ahmed Abdeen Hamed wrote: > Yes, of course! > > Attached is a tiny dataset that reproduces the problem, and the script that > I am using to generate the network. And, you are right indeed. Somehow, the > vertices are visualized as a list not as individuals as shown down here: > [image: Inline image 1] > > Thanks very much, > > -Ahmed > > > > > On Thu, Jan 8, 2015 at 6:53 PM, Tamas Nepusz <[email protected]> wrote: > > > Judging from your earlier screenshot, it seems like the labels are *lists* > > of > > hashtags and not individual hashtags (as the function assumes). Can you > > post > > a small, reproducible, self-contained example that demonstrates the > > problem? > > > > T. > > > > On 01/08, Ahmed Abdeen Hamed wrote: > > > Yes, thank you! > > > > > > The function is really simple, it works correctly in other context except > > > this one. Here is the implementation: > > > > > > def is_hashtag(vertex): > > > return vertex["name"].startswith("#") > > > > > > -Ahmed > > > > > > > > > > > > On Thu, Jan 8, 2015 at 4:59 PM, Tamas Nepusz <[email protected]> wrote: > > > > > > > Have you confirmed that your is_hashtag() function is working > > correctly? > > > > For > > > > one thing, it seems to me that each vertex contains multiple hash > > tags, so > > > > it > > > > could be the case that is_hashtag() is simply returning False for all > > the > > > > vertices. > > > > > > > > T. > > > > > > > > On 01/08, Ahmed Abdeen Hamed wrote: > > > > > It is still shows the hashtags even though they shouldn't. Here is > > small > > > > > screenshot that shows that there are hashtag appearing. What am I > > doing > > > > > wrong? > > > > > > > > > > -Ahmed > > > > > > > > > > > > > > > [image: Inline image 1] > > > > > > > > > > On Thu, Jan 8, 2015 at 4:15 PM, Tamas Nepusz <[email protected]> > > wrote: > > > > > > > > > > > > visual_style["vertex_label"] = ["" if is_hashtag(vertex) else > > > > > > > vertex["name"] for vertex in g.vs] > > > > > > > > > > > > > > However, there is a glitch. Suggestions? > > > > > > Your code seems okay; what is the problem with it? How did you try > > to > > > > plot > > > > > > the > > > > > > graph and what glitch did you see? > > > > > > > > > > > > -- > > > > > > T. > > > > > > > > > > > > > > > > > > > > > > -- > > > > T. > > > > > > > > -- > > T. > > > #!/usr/local/bin/python > import csv > import igraph > from igraph import * > from itertools import chain > #reader = csv.DictReader(open("wekarules-k-k-h-all.csv"), dialect="excel") > #reader = csv.DictReader(open("drug-hash-4viz.csv"), dialect="excel") > #reader = csv.DictReader(open("mjd.ALL.2162014.csv"), dialect="excel") > reader = csv.DictReader(open("network-sample-problematic.csv"), > dialect="excel")#network-sample-problematic.csv#kh-all-graph-validated.csv > g = igraph.Graph.DictList(vertices=None, edges=reader) > #del g.es()[None] > g.to_undirected() > g.simplify() > > layout = g.layout_fruchterman_reingold() > > def is_hashtag(vertex): > return vertex["name"].startswith("#") > > visual_style = {} > > visual_style["vertex_color"] = ["red" if is_hashtag(vertex) else "blue" for > vertex in g.vs] > visual_style["vertex_size"] = [11 if is_hashtag(vertex) else 23 for vertex in > g.vs] > visual_style["vertex_label"] = ["" if is_hashtag(vertex) else g.vs["name"] > for vertex in g.vs] > visual_style["vertex_label_size"] = 7 > visual_style["edge_width"] = 1 > visual_style["edge_color"] =["pink"] > visual_style["layout"] = layout > visual_style["bbox"] = (1700, 1700) > visual_style["margin"] = 50 > plot(g, > "/Users/ahamed/Publications/JBI-SI-GoodTemplate/ddi-network-vis-kh-labeled.pdf",**visual_style) > #plot(g, **visual_style) > source,target > benadryl,#zzzzz > benadryl,#zzzzzzz > benadryl,advil > benadryl,flonase > benadryl,ibuprofen > carafate,#apc > carafate,#gastrointestinaltract > carafate,#heyjai > carafate,#islamic > carafate,#lilalo > carafate,#mejordisco > carafate,#nexium > carafate,#ulcers > carafate,nexium > carafate,protonix > clarinex,#aids > clarinex,#ipad > clarinex,#skinswelling > clarinex,claritin > claritin,#achhhuu > claritin,#allergies > claritin,#allergiescansuckad > claritin,#boom > claritin,#dickforlunchladies > claritin,#diflucan > claritin,#dogsbehavingbadly > claritin,#fastbreak2! > claritin,#fuckallergies -- T. _______________________________________________ igraph-help mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/igraph-help
