当前位置: 首页>>代码示例>>Python>>正文


Python pydot.graph_from_dot_data函数代码示例

本文整理汇总了Python中pydot.graph_from_dot_data函数的典型用法代码示例。如果您正苦于以下问题:Python graph_from_dot_data函数的具体用法?Python graph_from_dot_data怎么用?Python graph_from_dot_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了graph_from_dot_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: draw_tree

def draw_tree(clf,sub_columns):
    print "绘制图"
    import pydot,StringIO
    dot_data = StringIO.StringIO()
    tree.export_graphviz(clf, out_file=dot_data,feature_names=sub_columns,max_depth=5)
    dot_data.getvalue()
    pydot.graph_from_dot_data(dot_data.getvalue())
    graph = pydot.graph_from_dot_data(dot_data.getvalue())
    graph.write_png('titanic.png')
开发者ID:mrcheng0910,项目名称:url_lexical_analysis,代码行数:9,代码来源:datamining.py

示例2: test_graph_with_shapefiles

    def test_graph_with_shapefiles(self):
        shapefile_dir = os.path.join(test_dir, 'from-past-to-future')
        # image files are omitted from sdist
        if not os.path.isdir(shapefile_dir):
            warnings.warn('Skipping tests that involve images, '
                          'they can be found in the `git` repository.')
            return
        dot_file = os.path.join(shapefile_dir, 'from-past-to-future.dot')


        pngs = [
            os.path.join(shapefile_dir, fname) for
            fname in os.listdir(shapefile_dir)
            if fname.endswith('.png')]

        f = open(dot_file, 'rt')
        graph_data = f.read()
        f.close()

        #g = dot_parser.parse_dot_data(graph_data)
        graphs = pydot.graph_from_dot_data(graph_data)
        (g,) = graphs
        g.set_shape_files( pngs )

        jpe_data = g.create( format='jpe' )

        hexdigest = sha256(jpe_data).hexdigest()
        hexdigest_original = self._render_with_graphviz(
            dot_file, encoding='ascii')
        self.assertEqual( hexdigest, hexdigest_original )
开发者ID:erocarrera,项目名称:pydot,代码行数:30,代码来源:pydot_unittest.py

示例3: positionGraph

def positionGraph():
  """Uses graphviz to position nodes of the graph.
  """
  try:
    import pydot
  except ImportError:
    return jsonify({})

  graph = pydot.Dot()

  for node_id, node in request.json['nodes'].iteritems():
    graph.add_node(pydot.Node(node_id))
  for edge in request.json['edges'].itervalues():
    graph.add_edge(pydot.Edge(edge[0], edge[1]))

  new_graph = pydot.graph_from_dot_data(graph.create_dot())

  # calulate the ratio from the size of the bounding box
  ratio = new_graph.get_bb()
  origin_left, origin_top, max_left, max_top = [float(p) for p in
    new_graph.get_bb().strip('"').split(',')]
  ratio_top = max_top - origin_top
  ratio_left = max_left - origin_left

  preference_dict = dict()
  for node in new_graph.get_nodes():
    # skip technical nodes
    if node.get_name() in ('graph', 'node', 'edge'):
      continue
    left, top = [float(p) for p in node.get_pos()[1:-1].split(",")]
    preference_dict[node.get_name().strip('"')] = dict(
      top=1-(top/ratio_top),
      left=1-(left/ratio_left),)

  return jsonify(preference_dict)
开发者ID:PanosBarlas,项目名称:dream,代码行数:35,代码来源:__init__.py

示例4: displayGraph

    def displayGraph(self):
        dot = self.graph.write(fmt="dot")

        import pydot

        dotgraph = pydot.graph_from_dot_data(dot)

        # Tmpfile
        import tempfile

        fh = tempfile.NamedTemporaryFile(suffix=".png")

        # dotgraph.write('graph.dot')
        dotgraph.write_png(fh.name)

        image = wx.Image(fh.name, wx.BITMAP_TYPE_ANY)

        fh.close()

        # Init the panel
        panel = GraphPanel(self.parent, image)
        panel.identifierTag = "Huffmann Tree"

        # Show the panel
        self.parent.AddPage(panel, "Huffmann Tree")
开发者ID:GaretJax,项目名称:sourcecoding,代码行数:25,代码来源:huffmann.py

示例5: drawDecisionTree

def drawDecisionTree(dt, filename, featureNames, classNames):
    dot_data = StringIO()
    print featureNames
    print classNames
    tree.export_graphviz(dt, out_file=dot_data, feature_names=featureNames, class_names=classNames, rounded=True, special_characters=True, filled=True)
    graph = pydot.graph_from_dot_data(dot_data.getvalue())
    graph.write_png(filename) 
开发者ID:doubaoatthu,项目名称:UWRoutingSystem,代码行数:7,代码来源:server.py

示例6: test_attribute_with_implicit_value

    def test_attribute_with_implicit_value(self):

        d = 'digraph {\na -> b[label="hi", decorate];\n}'
        g = pydot.graph_from_dot_data(d)
        attrs = g.get_edges()[0].get_attributes()

        self.assertEqual('decorate' in attrs, True)
开发者ID:krzysbaranski,项目名称:pydot,代码行数:7,代码来源:pydot_unittest.py

示例7: layout_graph

def layout_graph(graph, fname):
    print('writing un-layouted graph to "%s.dot"' % fname)

    graph.set_overlap("scale")
    dot = graph.create_dot()
    f = open("%s.dot" % fname, "w")
    f.write(dot)
    f.close()

    neato_dot = subprocess.check_output(["/usr/bin/neato", "-Tdot", "%s.dot" % fname])
    neato_png = subprocess.check_output(["/usr/bin/neato", "-Tpng", "%s.dot" % fname])
    neato_pdf = subprocess.check_output(["/usr/bin/neato", "-Tpdf", "%s.dot" % fname])
    print('writing layouted graph to "%s.dot.layouted.dot"' % fname)
    f = open("%s.dot.layouted.dot" % fname, "w")
    f.write(neato_dot)
    f.close()
    print('writing layouted graph to "%s.dot.png"' % fname)
    f = open("%s.dot.png" % fname, "w")
    f.write(neato_png)
    f.close()
    print('writing layouted graph to "%s.dot.pdf"' % fname)
    f = open("%s.dot.pdf" % fname, "w")
    f.write(neato_pdf)
    f.close()

    print("re-reading layouted dot from internal variable")
    graph = pydot.graph_from_dot_data(neato_dot)
    return graph
开发者ID:Benocs,项目名称:core,代码行数:28,代码来源:core-topogen_node_pos.py

示例8: read_dot

def read_dot(path):
    """Return a NetworkX MultiGraph or MultiDiGraph from a dot file on path.


    Parameters
    ----------
    path : filename or file handle

    Returns
    -------
    G : NetworkX multigraph
        A MultiGraph or MultiDiGraph.  
    
    Notes
    -----
    Use G=nx.Graph(nx.read_dot(path)) to return a Graph instead of a MultiGraph.
    """
    try:
        import pydot
    except ImportError:
        raise ImportError("read_dot() requires pydot",
                          "http://dkbza.org/pydot.html/")

    data=path.read()        
    P=pydot.graph_from_dot_data(data)
    return from_pydot(P)
开发者ID:Bludge0n,项目名称:AREsoft,代码行数:26,代码来源:nx_pydot.py

示例9: loadtasksdot

def loadtasksdot(fp):
    import pydot
    graphs = pydot.graph_from_dot_data(fp.read())
    (g2,) = graphs
    tasks = []
    tasksd = {}
    # if present use the attribute cost
    for n in g2.get_nodes():   
        ad =      n.get_attributes()
        #print n.get_name(),[a for a in ad]
        t = MTask(n.get_name(),float(ad.get("cost",1)),int(ad.get("items",1)),int(ad.get("maxnp",defaultcore)),int(ad.get("deadline",MTask.deadlinemaxtime)),float(ad.get("reductioncost",0)),int(ad.get("evennp",0)) != 0)
        tasks.append(t)
        tasksd[t.id] = t
    # if present use the attribute cost
    for e in g2.get_edges():
        #get_source
        #get_destination
        #get_attributes
        st = tasksd.get(e.get_source(),None)
        if st is None:
            st = MTask(e.get_source(),1,1,defaultcore)
            tasks.append(st)
            tasksd[st.id] = st
        dt = tasksd.get(e.get_destination(),None)
        if dt is None:
            dt = MTask(e.get_destination(),1,1,defaultcore)
            tasks.append(dt)
            tasksd[dt.id] = dt
        dt.parents.append(MTaskEdge(st,dt,float(e.get_attributes().get("delay",0)),float(e.get_attributes().get("reduction",0))))

        #print e.get_source(),e.get_destination(),[a for a in e.get_attributes().iteritems()]
    return tasks
开发者ID:eruffaldi,项目名称:taskschedule,代码行数:32,代码来源:sched.py

示例10: graph_to_page

def graph_to_page():
    file_vals = next(request.files.values())
    file_contents = file_vals.stream.read().decode('utf-8')
    file_contents = pydot.graph_from_dot_data(file_contents).to_string()
    compressed = zlib.compress(file_contents.encode('utf-8'), 9)
    encoded = urlsafe_b64encode(compressed)
    return request.host_url + "view?s=" + encoded.decode('utf-8')
开发者ID:odeits-vidder,项目名称:GaaS,代码行数:7,代码来源:app.py

示例11: classfyWithScipy

def classfyWithScipy(dataSet,labels,dataToClassfy):
    clf = tree.DecisionTreeClassifier(criterion="entropy").fit(dataSet,labels)
    dot_data = StringIO.StringIO() 
    tree.export_graphviz(clf, out_file=dot_data) 
    graph = pydot.graph_from_dot_data(dot_data.getvalue()) 
    graph.write_pdf("entropy.pdf") 
    return clf.predict(dataToClassfy)
开发者ID:noah-lcf,项目名称:PythonEx,代码行数:7,代码来源:trees.py

示例12: mainTree

def mainTree():
	header=re.sub(' |\t','','id|gender|age|height|edu|salary|nation|car|house|body|face|hair|\
	smoke|drink|child|parent|bmi|where0|where1|\
	marriage0|marriage1|look0|look1|where2').split('|')
	MaleData=pd.read_csv('/home/idanan/jiayuan/code/resources/transed_M.txt',names=header,sep='|')
	FemaleData=pd.read_csv('/home/idanan/jiayuan/code/resources/cluster_female.txt',names=header+['class'],sep='|')
	matches=matchDict('/home/idanan/jiayuan/code/resources/lovers_ids.txt')
	FemaleData['id']=FemaleData['id'].map(partial(match,matches=matches))
	FemaleClass=FemaleData[['id','class']]
	newMaleData=concatData(MaleData,FemaleClass)
	MaleArrays=scaleData(newMaleData,['id','gender'])
	pca=factors(MaleArrays[:,:-1],17)
	print 'PCA explained variance:', sum(pca.explained_variance_ratio_)
	pcaMaleArray=pca.transform(MaleArrays[:,:-1])
	MaleArrays=np.c_[pcaMaleArray,MaleArrays]


	trainData,testData=departData(MaleArrays,0.9)
	trainModel=decisionModel(trainData)

	dot_data = StringIO()
	tree.export_graphviz(trainModel, out_file=dot_data)
	graph = pydot.graph_from_dot_data(dot_data.getvalue())
	graph.write_pdf("/home/idanan/jiayuan/code/resources/marriage.pdf") 
	

	rate=test(trainModel,testData)
	print 'Decision Model true rate',rate
开发者ID:yowenter,项目名称:jiayuan,代码行数:28,代码来源:marryModel.py

示例13: main

def main():
	if (len(sys.argv) < 2):
		print("One Argument Required; Training Set")
		return
	X_train, Y_train = ParseTraining(sys.argv[1])
    #X_test, Y_test = ParseTraining(sys.argv[2])
    #X_train, X_test, Y_train, Y_test = cross_validation.train_test_split(X, Y, test_size=0.2, random_state=99)
    #X_train, X_test, Y_train, Y_test = X, X, Y, Y
    #clf = tree.DecisionTreeClassifier()
	clf = tree.DecisionTreeClassifier(max_depth=6)
    #clf = OneVsRestClassifier(SVC(kernel="linear", C=0.025))
    #clf = RandomForestClassifier(max_depth=6, n_estimators=10, max_features=1)
    #clf = SVC(kernel="linear", C=0.025)
    #clf = AdaBoostClassifier()
    #clf = SVC(gamma=2, C=1)
	clf = clf.fit(X_train, Y_train)


    #feature_names = ["partAvg", "recavg", "latency", "ReadRate"]
	feature_names = ["partConf", "recAvg", "latency", "ReadRate", "homeconf"]
    #feature_names = ["partAvg", "recAvg", "recVar", "ReadRate"]
    #feature_names = ["partAvg", "recAvg", "recVar"]
    #feature_names = ["recAvg", "recVar", "Read"]
    #feature_names = ["partAvg", "recVar"]
    ##class_names = ["Partition", "OCC", "2PL"]
    #class_names = ["OCC", "2PL"]
	class_names = ["Partition", "No Partition"]
	dot_data = StringIO()
	tree.export_graphviz(clf, out_file=dot_data,
						feature_names=feature_names,
						class_names=class_names,
						filled=True, rounded=True,
						special_characters=True)
	graph = pydot.graph_from_dot_data(dot_data.getvalue())
	graph.write_png("partition.png")
开发者ID:totemtang,项目名称:ACC-Classifier,代码行数:35,代码来源:single-partition.py

示例14: make_tree_test

def make_tree_test():
    from sklearn import tree
    
    import StringIO
    
    import pydot
    
    from IPython.display import display, Image     
    
    x,y,dates,movies = load_data()
    
    #x =  add_missed_value_indicator(x)   
                
    test_x, train_x, test_y, train_y = create_test_train_set(x, y)          
    
    clf = tree.DecisionTreeClassifier(min_samples_split=3000)
    
    fit = clf.fit(train_x,train_y)
    
    dot_data = StringIO.StringIO()
    
    tree.export_graphviz(fit, 
       feature_names=train_x.columns,
       class_names=["1","2","3","4","5"],
       out_file=dot_data)
    
    graph = pydot.graph_from_dot_data(dot_data.getvalue())   
    
    graph[0].write_png("tree_toy.png")
    
    img = Image(graph[0].create_png()) 
    
    display(img)

    return fit
开发者ID:yonatan-katz,项目名称:summer_course_2016,代码行数:35,代码来源:netflix.py

示例15: draw_tree

def draw_tree(clf):
    import pydot
    import StringIO
    output = StringIO.StringIO()
    tree.export_graphviz(clf, out_file=output)
    graph = pydot.graph_from_dot_data(output.getvalue())
    graph.write_pdf('tree.pdf')
开发者ID:lispc,项目名称:COMP8502,代码行数:7,代码来源:tree_test.py


注:本文中的pydot.graph_from_dot_data函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。