source: orange/orange/doc/reference/output.py @ 8042:ffcb93bc9028

Revision 8042:ffcb93bc9028, 1.3 KB checked in by markotoplak, 3 years ago (diff)

Hierarchical clustering: also catch RuntimeError when importing matplotlib (or the documentation could not be built on server).

Line 
1# Description: Shows how to define new output format
2# Category:    kernel
3# Classes:     Contingency, ContingencyAttrClass
4# Uses:        monk1
5# Referenced:  contingency.htm
6
7import orange
8
9def printTabDelimContingency(c):
10    if c.innerVariable.varType != orange.VarTypes.Discrete or \
11       c.outerVariable.varType != orange.VarTypes.Discrete:
12        raise Exception("printTabDelimContingency can only handle discrete contingencies")
13   
14    res = ""
15    for v in c.innerVariable.values:
16        res += "\t%s" % v
17    res += "\n"
18    for i in range(len(c.outerVariable.values)):
19        res += c.outerVariable.values[i]
20        for v in c[i]:
21            res += "\t%5.3f" % v
22        res += "\n"
23    return res
24
25orange.setoutput(orange.Contingency, "tab", printTabDelimContingency)
26
27data = orange.ExampleTable("monk1")
28cont = orange.ContingencyAttrClass("e", data)
29
30print "\n*** Dump in format 'tab' ***\n"
31print cont.dump("tab")
32
33orange.setoutput(orange.Contingency, "repr", printTabDelimContingency)
34print "\n*** Print after 'repr' is set ***\n"
35print cont
36
37print "\n*** Reverse-quoting after 'repr' is set ***\n"
38print `cont`
39
40print "\n*** Print after 'str' is set ***\n"
41orange.setoutput(orange.Contingency, "str", printTabDelimContingency)
42print cont
43
44orange.removeoutput(orange.Contingency, "repr")
45orange.removeoutput(orange.Contingency, "str")
Note: See TracBrowser for help on using the repository browser.