English 中文(简体)
• 改变IGraph-Python含有特定vert的edge色
原标题:Can i change the colour of edges containing specific vertices in IGraph-Python

我制作了一个直线图表,并通过一个方案,发现其中的所有周期。 在编造图表之后,图一想改变包含周期中 involved的边缘的颜色。

我正在使用图表。

请帮助

最佳回答

与此类似:

vertex_set = set(vertices_in_cycle)
g.es["color"] = "black"
red_edges = g.es.select(_source_in=vertex_set, _target_in=vertex_set)
red_edges["color"] = "red"

解释:

  1. <代码>g.es是图表中所有栏目。 (同样,g.vs是所有vert。)

  2. g.es["color"] lets you assign a value to the color attribute of all the edges in the graph. This edge attribute is used by the plotter to decide what color an edge should have. Therefore, in line 2, you are setting the color of all the edges to black. (Note: you could also use a list here instead of a simple string, or you could use HTML color notations for custom colors).

  3. 您可使用<代码>g.es作为清单,在这种情况下,您可取得图表的特定优势;例如,<代码>,例如,<<<<>>>/code>将给你贴近2。 这里没有使用,但很想知道。

  4. help(EdgeSeq.select)使你对此更感动;这里的问题是,在第3行中,你选择了所有顶点,而两端点都位于外墙上。 选定的对口存放在<代码>red_vants变量上,其类型与g.es(即EdgeSeq)。

  5. 在最后一段中,你正在把所有边缘的彩色放在“条形”栏目中,即“红外线”和“条形”栏目中,这超越了你在第2行中确定的黑色。

请注意,上述法典将不仅标明周期的边缘,而且标明周期的所有cho。

<>Update:如果上述法典第3行不为你工作,你可以将第2和第3行改为:

g.es["color"] = ["red" if (edge.source in vertex_set and 
                           edge.target in vertex_set) else "black" 
                 for edge in g.es]
问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签