# source:orange/orange/doc/reference/graph_obj.py@6538:a5f65d7f0b2c

Revision 6538:a5f65d7f0b2c, 1.2 KB checked in by Mitar <Mitar@…>, 4 years ago (diff)

Made XPM version of the icon 32x32.

Line
1# Description: Shows how to use graphs
2# Category:    general
3# Classes:     Graph
4# Uses:
5# Referenced:  graph.htm
6
7import orange
8
9graph = orange.GraphAsMatrix(4, 0, objectsOnEdges = 1)
10graph.objects = ["Age", "Gender", "Height", "Weight"]
11
12graph["Age", "Gender"] = "a string"
13# commented out: causes differences in regression tests between machines
14#graph["Age", "Height"] = orange
15graph["Gender", "Height"] = [1, 2, 3]
16print graph.getEdges()
17
18print graph[1, 2]
19print graph["Gender", "Height"]
20print graph["Age", "Gender"]
21print graph["Age", "Height"]
22
23graph.objects = {}
24graph.objects["Age"] = 0
25graph.objects["Gender"] = 1
26graph.objects["Height"] = 2
27
28print graph["Age", "Gender"]
29try:
30    print graph["Gender", "Height"]
31except:
32    print 'graph["Gender", "Height"] failed'
33
34print graph.getNeighbours("Age")
35graph.returnIndices = 1
36print graph.getNeighbours("Age")
37
38
39graph = orange.GraphAsMatrix(5, 0, 3)
40print graph[4, 1]
41graph[4, 1, 1]=12
42print graph[4, 1, 1]
43print graph[4, 1]
44
45print graph.edgeExists(4, 1)
46print graph.edgeExists(4, 2)
47print graph.edgeExists(4, 1, 1)
48print graph.edgeExists(4, 1, 2)
49
50e = graph[4, 1]
51e[1]
52e[2]
53e[1] = None
54e[2] = 3
55print graph.edgeExists(4, 1, 1)
56print graph.edgeExists(4, 1, 2)
57print e
58graph[4, 1]=None
59print e
Note: See TracBrowser for help on using the repository browser.