本文整理汇总了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')
示例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 )
示例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)
示例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")
示例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)
示例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)
示例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
示例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)
示例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
示例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')
示例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)
示例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
示例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")
示例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
示例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')