Code Monkey home page Code Monkey logo

pydot's Introduction

CI PyPI Code style: black

About

pydot:

  • is an interface to Graphviz,
  • can parse and dump into the DOT language used by GraphViz,
  • is written in pure Python,

and networkx can convert its graphs to pydot.

Development occurs at GitHub, where you can report issues and contribute code.

Examples

The examples here will show you the most common input, editing and output methods.

Input

No matter what you want to do with pydot, it will need some input to start with. Here are 3 common options:

  1. Import a graph from an existing DOT-file.

    Use this method if you already have a DOT-file describing a graph, for example as output of another program. Let's say you already have this example.dot (based on an example from Wikipedia):

    graph my_graph {
       bgcolor="yellow";
       a [label="Foo"];
       b [shape=circle];
       a -- b -- c [color=blue];
    }

    Just read the graph from the DOT-file:

    import pydot
    
    graphs = pydot.graph_from_dot_file("example.dot")
    graph = graphs[0]
  2. or: Parse a graph from an existing DOT-string.

    Use this method if you already have a DOT-string describing a graph in a Python variable:

    import pydot
    
    dot_string = """graph my_graph {
        bgcolor="yellow";
        a [label="Foo"];
        b [shape=circle];
        a -- b -- c [color=blue];
    }"""
    
    graphs = pydot.graph_from_dot_data(dot_string)
    graph = graphs[0]
  3. or: Create a graph from scratch using pydot objects.

    Now this is where the cool stuff starts. Use this method if you want to build new graphs from Python.

    import pydot
    
    graph = pydot.Dot("my_graph", graph_type="graph", bgcolor="yellow")
    
    # Add nodes
    my_node = pydot.Node("a", label="Foo")
    graph.add_node(my_node)
    # Or, without using an intermediate variable:
    graph.add_node(pydot.Node("b", shape="circle"))
    
    # Add edges
    my_edge = pydot.Edge("a", "b", color="blue")
    graph.add_edge(my_edge)
    # Or, without using an intermediate variable:
    graph.add_edge(pydot.Edge("b", "c", color="blue"))

    Imagine using these basic building blocks from your Python program to dynamically generate a graph. For example, start out with a basic pydot.Dot graph object, then loop through your data while adding nodes and edges. Use values from your data as labels, to determine shapes, edges and so forth. This way, you can easily build visualizations of thousands of interconnected items.

  4. or: Convert a NetworkX graph to a pydot graph.

    NetworkX has conversion methods for pydot graphs:

    import networkx
    import pydot
    
    # See NetworkX documentation on how to build a NetworkX graph.
    
    graph = networkx.drawing.nx_pydot.to_pydot(my_networkx_graph)

Edit

You can now further manipulate your graph using pydot methods:

  • Add further nodes and edges:

    graph.add_edge(pydot.Edge("b", "d", style="dotted"))
  • Edit attributes of graph, nodes and edges:

    graph.set_bgcolor("lightyellow")
    graph.get_node("b")[0].set_shape("box")

Output

Here are 3 different output options:

  1. Generate an image.

    To generate an image of the graph, use one of the create_*() or write_*() methods.

    • If you need to further process the output in Python, the create_* methods will get you a Python bytes object:

      output_graphviz_svg = graph.create_svg()
    • If instead you just want to save the image to a file, use one of the write_* methods:

      graph.write_png("output.png")
  2. Retrieve the DOT string.

    There are two different DOT strings you can retrieve:

    • The "raw" pydot DOT: This is generated the fastest and will usually still look quite similar to the DOT you put in. It is generated by pydot itself, without calling Graphviz.

      # As a string:
      output_raw_dot = graph.to_string()
      # Or, save it as a DOT-file:
      graph.write_raw("output_raw.dot")
    • The Graphviz DOT: You can use it to check how Graphviz lays out the graph before it produces an image. It is generated by Graphviz.

      # As a bytes literal:
      output_graphviz_dot = graph.create_dot()
      # Or, save it as a DOT-file:
      graph.write_dot("output_graphviz.dot")
  3. Convert to a NetworkX graph.

    Here as well, NetworkX has a conversion method for pydot graphs:

    my_networkx_graph = networkx.drawing.nx_pydot.from_pydot(graph)

More help

For more help, see the docstrings of the various pydot objects and methods. For example, help(pydot), help(pydot.Graph) and help(pydot.Dot.write).

More documentation contributions welcome.

Installation

From PyPI using pip:

pip install pydot

From source:

python setup.py install

Dependencies

  • pyparsing: used only for loading DOT files, installed automatically during pydot installation.

  • GraphViz: used to render graphs as PDF, PNG, SVG, etc. Should be installed separately, using your system's package manager, something similar (e.g., MacPorts), or from its source.

Troubleshooting

How to enable logging

pydot uses Python's standard logging module. To see the logs, assuming logging has not been configured already:

>>> import logging
>>> logging.basicConfig(level=logging.DEBUG)
>>> import pydot
DEBUG:pydot:pydot initializing
DEBUG:pydot:pydot <version>
DEBUG:pydot.core:pydot core module initializing
DEBUG:pydot.dot_parser:pydot dot_parser module initializing

Warning: When DEBUG level logging is enabled, pydot may log the data that it processes, such as graph contents or DOT strings. This can cause the log to become very large or contain sensitive information.

Advanced logging configuration

  • Check out the Python logging documentation and the logging_tree visualizer.
  • pydot does not add any handlers to its loggers, nor does it setup or modify your root logger. The pydot loggers are created with the default level NOTSET.
  • pydot registers the following loggers:
    • pydot: Parent logger. Emits a few messages during startup.
    • pydot.core: Messages related to pydot objects, Graphviz execution and anything else not covered by the other loggers.
    • pydot.dot_parser: Messages related to the parsing of DOT strings.

License

Distributed under an MIT license.

Contacts

Current maintainer(s):

  • Łukasz Łapiński <lukaszlapinski7 (at) gmail (dot) com>

Past maintainers:

  • Sebastian Kalinowski <sebastian (at) kalinowski (dot) eu> (GitHub: @prmtl)
  • Peter Nowee <peter (at) peternowee (dot) com> (GitHub: @peternowee)

Original author: Ero Carrera <ero (dot) carrera (at) gmail (dot) com>

pydot's People

Contributors

alexanderdokuchaev avatar ashafix avatar brlam avatar carlos-jenkins avatar chrisburr avatar dchimeno avatar dependabot[bot] avatar ferdnyc avatar gustavla avatar hoverjmt avatar hrishikeshrt avatar hugovk avatar iari avatar johnyf avatar kg86 avatar leycec avatar lgerardsri avatar lkk7 avatar nanno-lang avatar nlhepler avatar pauloxnet avatar peterjc avatar peternowee avatar pnb avatar prmtl avatar step-security-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pydot's Issues

"strict" directive not properly handled (1.0.2)

From the DOT user's guide at
http://www.graphviz.org/Documentation/dotguide.pdf: "In the top-level graph
heading, a graph may be declared a strict digraph. This forbids the
creation of self-arcs and multi-edges; they are ignored in the input file."

The pydot parser does not do this. It creates the self-arcs and multi-edges
anyway, regardless of whether a graph is declared as "strict."

Original issue reported on code.google.com by [email protected] on 31 Jul 2008 at 10:26

: included as value for any attribute causes error

Whenever a colon(:) occurs in the value field of any of the
attributes, pydot throws an error. Please someone fix this as soon as
possible.

It is very likely to have ":" in the value provided to the URL
attribute. In my case I tried to create a node with URL='http://
www.google.com' but unfortunately this does not work. If I remove the
colon i.e give URL='http//www.google.com', it works without any error
but that doesn't serve the purpose. So it needs to be handled.

Original issue reported on code.google.com by [email protected] on 24 Mar 2009 at 2:32

Edge has no attribute penwidth

What steps will reproduce the problem?
set_penwidth() or get_penwidth() don't work until they get added by 
pydot.EDGE_ATTRIBUTES.add('penwidth')

Original issue reported on code.google.com by [email protected] on 5 Sep 2010 at 4:30

set default attributes so following nodes can use this as default

Sorry I did not find a forum or group can send my question so I paste it
here. If not approperiate, please just remove it.

I want to figure out a way to set  default attributes for all fllowing
nodes' shape, but I could not find a method that can generate 'node
[shape='box']' sentense as ususaly seen in Dot file. 

Any tips? 

Original issue reported on code.google.com by [email protected] on 5 Feb 2008 at 11:03

find_graphviz() fails on Windows with GraphViz 2.26.3

GraphViz 2.26.3 (which I installed just today) uses a different registry key to 
store the install path.  Instead of "SOFTWARE\ATT\Graphviz" the key used is 
"Software\AT&T Research Labs\GraphViz".

The simplest solution is to check the both locations.

for regkey in ("SOFTWARE\ATT\Graphviz",
               "SOFTWARE\AT&T Research Labs\GraphViz") :
    try :
        hkey = win32api.RegOpenKeyEx( win32con.HKEY_LOCAL_MACHINE,
            regkey, 0, win32con.KEY_QUERY_VALUE )
    except win32api.error :
        continue
    else :
        break
else :
    # Raise error that registry not found
    raise Exception("Unable to find graphviz")

(Modified to fit whatever style conventions you have.)

Since Graphviz puts its bin in the path, a simpler, more logical check, would 
be to just call "dot -V" (or whatever program) and search the output for the 
string "graphviz".

Original issue reported on code.google.com by [email protected] on 15 Jul 2010 at 2:49

  • Merged into: #29

no URL attr leads to crash when output format is cmap

What steps will reproduce the problem?
import pydot
graph = pydot.Dot('graphname', graph_type='graph')
node_a = pydot.Node("Node A", style="filled", fillcolor="#21e1d2", 
shape="folder")
graph.add_node(node_a)

#graph.write_jpg('hu.jpeg')
#graph.write_gif('hu.gif')
#print graph.create(format="jpeg")
graph.write_cmap('hu.cmap')
print graph.create(format="cmap")
#graph.write_dot('hu.dot')

# leads to
# ========

#Traceback (most recent call last):
#  File "test_pydot2.py", line 9, in <module>
#    graph.write_cmap('hu.cmap')
#  File "build/bdist.linux-i686/egg/pydot.py", line 1602, in <lambda>
#  File "build/bdist.linux-i686/egg/pydot.py", line 1696, in write
#TypeError: argument 1 must be string or buffer, not list


Please provide any additional information below.

patch:

+++ pydot.py    2010-09-01 11:25:11.000000000 +0200
@@ -1807,5 +1807,5 @@

         os.unlink(tmp_name)

-        return stdout_output
+        return stdout_output or ''




Original issue reported on code.google.com by [email protected] on 1 Sep 2010 at 9:29

Example some wrong with version 1.0.2

What steps will reproduce the problem?
1. install pydot 1.0.2
2. compile the example 

What is the expected output? What do you see instead?
TypeError: cannot concatenate 'str' and 'int' objects

What version of the product are you using? On what operating system?
graphviz 2.18
python 2.5+
pyparsing 1.4.11
pydot 1.0.2
win vista and winxp sp2

Please provide any additional information below.

i find the example at http://dkbza.org/pydot.html like this:

import pydot 
edges=[(1,2), (1,3), (1,4), (3,4)] 
g=pydot.graph_from_edges(edges) 
g.write_jpeg('graph_from_edges_dot.jpg', prog='dot') 

but i get error

i change it like this

edges=[('1','2'), ('1','3'), ('1','4'), ('3','4')]

that is ok.

Original issue reported on code.google.com by [email protected] on 7 May 2008 at 3:49

Path detection of GV .EXEs fails on WIN7 64 bit.

What steps will reproduce the problem?
1. Install pydot
2. Try creating a .jpg of a graph.
3. Observe that pydot fails to find the .EXEs of GV

What is the expected output? What do you see instead?
I expect pydot to find the executables :)

What version of the product are you using? On what operating system?
1.0.2. Windows 7 64 bit.

Please provide any additional information below.
First of all you should know that the executables that pydot needs are 
found in the directory - C:\Program Files (x86)\Graphviz2.26.3\bin .

The first method for detecting the path of the executables (using pywin32) 
doesnt work. I had to delete the first case, and put C:\Program Files 
(x86)\Graphviz2.26.3\bin in the PATH, and then everything was fine :).

Original issue reported on code.google.com by [email protected] on 12 May 2010 at 7:04

  • Merged into: #37

find_graphviz() fails on Windows when no registry entry present

What steps will reproduce the problem?
1. Install Graphviz on Windows.
2. If it was created then remove the SOFTWARE\ATT\Graphviz key from the 
registry.
3. import pydot; pydot.find_graphviz()

What is the expected output? What do you see instead?
I would expect the registry check to fail and for the code to fall back to 
checking paths.  Instead, an (C++?) 
exception is raised when calling win32api.RegOpenKeyEx(...).

What version of the product are you using? On what operating system?
pydot 1.0.2, Graphviz 2.22.2 (?) on Windows XP

Please provide any additional information below.

The following alternate "Method 1" for find_graphviz() that uses winreg/_winreg 
appears to work:

    # Method 1 (Windows only)
    #
    if os.sys.platform == 'win32':

        # Get the GraphViz install path from the registry
        #
        try:
            import winreg  # Python 3.0+
        except:
            try:
                import _winreg as winreg  # Python 2.0+
            except:
                winreg = None

        if winreg is not None:
            hkey = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)

            try:
                gvkey = winreg.OpenKey(hkey, "SOFTWARE\\ATT\\Graphviz", 0, winreg.KEY_READ)

                if gvkey is not None:
                    path = winreg.QueryValueEx(gvkey, "InstallPath")[0]

                    if path is not None:
                        progs = __find_executables(path + os.sep + "bin")
                        if progs is not None :
                            #print "Used Windows registry"
                            return progs
            except:
                pass
            finally:
                winreg.CloseKey(hkey)

Original issue reported on code.google.com by [email protected] on 22 Apr 2009 at 8:07

Cluster nodes misses attributes

What steps will reproduce the problem?
1. generate a Cluster object "node"
2. try node.set_color("Red")
3. pydot will complain

Please provide any additional information below.
I found that cluster object lacked "set_color" and more,
so I had to add:
self.create_attribute_methods(CLUSTER_ATTRIBUTES)
to the end of Cluster.__init__ to get the cluster specific attributes

Original issue reported on code.google.com by [email protected] on 8 Apr 2008 at 11:05

There should be more committers

What steps will reproduce the problem?
1. Fix a bug in pydot (e.g. 17)
2. Produce a patch
3. Wait more than 6 months for the patch to be applied and the bug even 
acknowledged by the maintainers

What is the expected output? What do you see instead?

Bug should be acknowledged, marked as nextrelease or something.

What version of the product are you using? On what operating system?

1.0.2

Please provide any additional information below.

Folks, I know everyone is busy. I also have open source projects and I 
don't always get to them on time, but when people submit a patch I think 
you should at least send and ACK back.

Cheers,
Leo.


Original issue reported on code.google.com by [email protected] on 8 Feb 2010 at 1:35

Example code on homepage.

The current example code is in a single line:

# Now it's possible to use rank to lay out nodes at the same level

    graph = pydot.Dot('graphname', graph_type='digraph') subg = pydot.Subgraph('', rank='same') subg.add_node(pydot.Node('a')) graph.add_subgraph(subg) subg.add_node(pydot.Node('b')) subg.add_node(pydot.Node('c')) 




It would be nice to have it separated by line feeds to aid in easy 
copy-pasting. :)

~
musically_ut

Original issue reported on code.google.com by musically.ut on 24 Nov 2010 at 12:39

Are there plans to port pydot to Python 3.x

The python-graph team are working on porting our project to Python 3.x -
naturally we'd like to retain our support for pydot. Can any member of this
project comment if a python 3.x version is likely in the near future.

Thanks!

Original issue reported on code.google.com by [email protected] on 1 Oct 2009 at 11:24

Creating DOT nodes in subgraph with rank=same

What steps will reproduce the problem?
1. File attached - direct DOT text file works fine on simple test graph
2. Occurs when attempting to create table-like structure using multiple
node lines with rank=same. Works fine in direct DOT calls (where I'm using
much more complex structures including embedded clusters and subgraphs).
3. I've remove all comment lines to make sure they were not triggering the
problem (although I can't image why, it shortens the file).

What is the expected output? What do you see instead?
Instead of two lines of nodes, I receive a single long row.  The subgraphs
are not maintaining their independencies.

Let me know if you need additional information/data.

What version of the product are you using? On what operating system?
XP-SP3, DOT 2.21, pydot 1.02, Python 2.5, IDLE (python's standard IDE) for
testing purposes (to keep it simple).

Please provide any additional information below.
- Objective - create multi-tier embedded table structure using pydot.  I
can do this in DOT (directly, see attached sample).
- Objective - add distance values to edges which can be used in
least-distance calculations.
- Objective - create cluster structures as supported in DOT.

Suggestions (class extensions):
- support for Cluster function which is very useful in DOT.
- add_edge_list (not the graph_from_edge, but a full list of tuples)
- add_node_list (list with attributes)
- add_edge_chain - ordered list where each member is assumed to be linked
to the next member in the list. This is supported in DOT.
- add_edge_matrix(self, list_edges, length_subchain,
status_links_bidirectional) - ordered list that creates table-like grid
where automatic links are generated between vertical pairs and horizontal
pairs.  For example, if a list of 12 members (essentially 4 rows of 3
members) is passed, used the length_subchain (in this case 3) to parse out
horizontal edges.  If status_links_bidirectional==True, then link each row
(neighbor)member with the member in the row above it (so row 2, position 2
would link to row 1, position 2 and row 3, position 2) without having to
explicitly map out each each.


Original issue reported on code.google.com by [email protected] on 14 Feb 2009 at 9:09

Attachments:

incorrect path search in find_graphviz()

What steps will reproduce the problem?

  1. Install (multiple versions of) graphviz into multiple locations
  2. Include in PATH more than one directory containing graphviz
  3. call pydot.find_graphviz()

What is the expected output? What do you see instead?

I expect the first executable in the path. pydot.find_graphviz() finds the
last executable in the path.

What version of the product are you using? On what operating system?

pydot-0.9.10, python-2.5, Ubuntu 7.04 (Intel 32-bit)

Please provide any additional information below.
Reordering the loops and inserting breaks ought to produce correct results:

        for prg in progs.keys():
                for path in os.environ['PATH'].split(os.pathsep):
                        if os.path.exists(path+os.path.sep+prg):
                                progs[prg] = path+os.path.sep+prg
                                break
                        elif os.path.exists(path+os.path.sep+prg + '.exe'):
                                progs[prg] = path+os.path.sep+prg + '.exe'
                                break

Original issue reported on code.google.com by [email protected] on 18 Sep 2007 at 10:37

Problem with Graphviz path with space

What steps will reproduce the problem?
1. Install Graphviz to some directory with space e.g. C:\Program Files\...
2. Use pydot
3.

What is the expected output? What do you see instead?
Expected: pydot should be able to locate and execute appropriate executable
file in Graphviz
What I see: pydot does not found executable files.

What version of the product are you using? On what operating system?
Windows XP SP2
pydot 0.9.1
Python 2.4.4

Please provide any additional information below.
Workaround: 
modify pydot's code in find_graphviz() as follows:
            if os.path.exists(path+os.path.sep+prg):
                progs[prg] = path+os.path.sep+prg
            elif os.path.exists(path+os.path.sep+prg + '.exe'):
                # BEGIN Edited by Chat to add " to the path namew with spaces
                prog_path = path+os.path.sep+prg + '.exe'
                if (" " in prog_path):
                    prog_path = '"' + prog_path + '"'
                progs[prg] = prog_path
                # END Edited by Chat to add " to the path namew with spaces
    return progs


Original issue reported on code.google.com by [email protected] on 22 Jan 2008 at 6:52

Many warnings running test

What steps will reproduce the problem?
1. Change to test directory
2. python pydot_unittest.py

What is the expected output? What do you see instead?

Expected: no warnings or errors.

Actual: 

# python pydot_unittest.py 

test_add_style (__main__.TestGraphAPI) ... ok
test_attribute_with_implicit_value (__main__.TestGraphAPI) ... ok
test_create_simple_graph_with_node (__main__.TestGraphAPI) ... ok
test_executable_not_found_exception (__main__.TestGraphAPI) ... ok
test_graph_add_edge_argument_type (__main__.TestGraphAPI) ... ok
test_graph_add_node_argument_type (__main__.TestGraphAPI) ... ok
test_graph_add_subgraph_argument_type (__main__.TestGraphAPI) ... ok
test_graph_pickling (__main__.TestGraphAPI) ... ok
test_graph_with_shapefiles (__main__.TestGraphAPI) ... Warning: AI_icon was 
already in a rankset, ignored in cluster G
Warning: Biology_icon was already in a rankset, ignored in cluster G
Warning: Social_Networks_icon was already in a rankset, ignored in cluster G
Warning: Turing_icon was already in a rankset, ignored in cluster G
Warning: Rejewski_icon was already in a rankset, ignored in cluster G
Warning: Dertouzos_icon was already in a rankset, ignored in cluster G
Warning: Berners_Lee_icon was already in a rankset, ignored in cluster G

ok
test_graphviz_regression_tests (__main__.TestGraphAPI) ... 
###############Warning: node columns_foo_insider, port foo unrecognized
Warning: cluster_foo -> label_xxxxxxx: head not inside head cluster cluster_foo

#######################################Warning: hot_pink is not a known color.

###########Warning: slate_blue is not a known color.
Warning: hot pink is not a known color.

######################################################################Warning: 
layers not supported in jpe output

#Warning: layers not supported in jpe output

#Warning: layers not supported in jpe output

#############################Warning: using box for unknown shape DFDbox

##Warning: using box for unknown shape sdl_task
Warning: using box for unknown shape sdl_input_from_right
Warning: using box for unknown shape sdl_input_from_left
Warning: using box for unknown shape sdl_priority_input_from_right
Warning: using box for unknown shape sdl_priority_input_from_left
Warning: using box for unknown shape sdl_start
Warning: using box for unknown shape sdl_procedure_start
Warning: using box for unknown shape sdl_state
Warning: using box for unknown shape sdl_output_to_right
Warning: using box for unknown shape sdl_output_to_left
Warning: using box for unknown shape sdl_condition
Warning: using box for unknown shape sdl_save
Warning: using box for unknown shape sdl_stop
Warning: using box for unknown shape sdl_return
Warning: using box for unknown shape sdl_create
Warning: using box for unknown shape sdl_call
Warning: using box for unknown shape sdl_text
Warning: using box for unknown shape sdl_text_extension_from_left
Warning: using box for unknown shape sdl_text_extension_from_right
Warning: using box for unknown shape sdl_comment_from_left
Warning: using box for unknown shape sdl_comment_from_right
Warning: using box for unknown shape sdl_connector
Warning: using box for unknown shape sdl_set
Warning: using box for unknown shape sdl_reset
Warning: using box for unknown shape sdl_export

########################Warning: No such file or directory while opening jcr.gif
Warning: No or improper shapefile="jcr.gif" for node "n"
Warning: No such file or directory while opening jcr.gif
Warning: No or improper shapefile="jcr.gif" for node "x"

#####ok
test_keep_graph_type (__main__.TestGraphAPI) ... ok
test_keyword_node_id (__main__.TestGraphAPI) ... ok
test_keyword_node_id_to_string_no_attributes (__main__.TestGraphAPI) ... ok
test_keyword_node_id_to_string_with_attributes (__main__.TestGraphAPI) ... ok
test_multiple_graphs (__main__.TestGraphAPI) ... ok
test_my_regression_tests (__main__.TestGraphAPI) ... ####ok
test_names_of_a_thousand_nodes (__main__.TestGraphAPI) ... ok
test_numeric_node_id (__main__.TestGraphAPI) ... ok
test_quoted_node_id (__main__.TestGraphAPI) ... ok
test_quoted_node_id_to_string_no_attributes (__main__.TestGraphAPI) ... ok
test_subgraphs (__main__.TestGraphAPI) ... ok
test_unicode_ids (__main__.TestGraphAPI) ... ok

----------------------------------------------------------------------
Ran 22 tests in 253.656s

OK

What version of the product are you using? On what operating system?

SVN Revision 17

Please provide any additional information below.

Also, are there any docs anywhere?


Original issue reported on code.google.com by [email protected] on 26 Nov 2010 at 3:36

":" not working in node name when not pydot.needs_quote(name)

What steps will reproduce the problem?
>>> import pydot
>>> pydot.Node('a:').get_name()
'a'

What is the expected output?
'a:'

What do you see instead?
'a'

What version of the product are you using? On what operating system?
pydot-1.0.25 / GNU/Linux

Please provide any additional information below.

This works when pydot.needs_quotes(name). For example, it will work when name 
== ":a".

Original issue reported on code.google.com by [email protected] on 26 May 2011 at 8:09

Keep PyPI download link updated

pydot is only at v1.02 on PyPI http://pypi.python.org/pypi/pydot but has seen 
several significant updates since the 1.02 release. It would be nice if the 
pydot maintainers kept the PyPI download link, if not the actual packages 
uploaded to PyPI, in closer sync.

Original issue reported on code.google.com by [email protected] on 7 Apr 2011 at 6:58

pydot does not support unicode

What steps will reproduce the problem?

import pydot
n1 = u"Thérèse Doe"
n2 = u"Jean-Pierre Toué"

# Does not work
g = pydot.Dot()
g.add_edge(pydot.Edge(n1, n2))
g.write_jpeg('test.jpg')

# Works :)
g = pydot.Dot()
g.add_edge(pydot.Edge(n1.encode('UTF-8'), n2.encode('UTF-8')))
g.write_jpeg('test.jpg')

What version of the product are you using? On what operating system?

1.0.2, on Fedora 10.

Please provide any additional information below.

Originally filed here: https://bugzilla.redhat.com/show_bug.cgi?id=481786

Original issue reported on code.google.com by [email protected] on 3 Feb 2009 at 8:27

Bundle with required dependencies

Is it possible to provide alternative pydot download with dependencies
included? So that dependencies will be checked and upgraded/installed when
needed. 

Original issue reported on code.google.com by [email protected] on 19 May 2008 at 1:51

Problem with detecting path to GraphViz

I have a problem with finding of path to GraphViz system in pydot module 
version 1.0.2.
GraphVis catalog is  "C:\Program Files\Graphviz 2.21\bin" by default, but 
function find_graphvis() returned "None" value. It just because there 
was "C:\Program Files\ATT\Graphviz\bin" as a default path to binaries. 
Solving of problem is such


 # Method 3 (Windows only)
    #
    if os.sys.platform == 'win32':
        print 'win32'

        # Try and work out the equivalent of "C:\Program Files" on this
        # machine (might be on drive D:, or in a different language)
        #

        if os.environ.has_key('PROGRAMFILES'):

            # Note, we could also use the win32api to get this
            # information, but win32api may not be installed.

            #path = os.path.join(os.environ
['PROGRAMFILES'], 'ATT', 'GraphViz', 'bin')
            #print path

        #else:

            #Just in case, try the default...
            path = r"C:\Program Files\Graphviz 2.21\bin"
            print path

        progs = __find_executables(path)
        print progs

        if progs is not None :

            #print "Used default install location"
            return progs




Original issue reported on code.google.com by [email protected] on 28 Jan 2009 at 1:03

PyDot: cannot enter special charactes as ':' ',' '#' etc in node or label name

What steps will reproduce the problem?
1. create a diagram using pydot.
2. put one of the nodes name as 'Testnode:###@'
3. or put labels on arrow as 'testlabel:###,@'

What is the expected output? What do you see instead?
It Should consider the name as a string and should be shown on the node/label

What version of the product are you using? On what operating system?
pydot 1.0.2

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 20 Aug 2010 at 10:00

  • Merged into: #28

attributes missing from Dot

What steps will reproduce the problem?
>>> import pydot
>>> import pickle
>>> test = pydot.Dot()
>>> output = open("data.pkl", "wb")
>>> pickle.dump(test, output)

What is the expected output? What do you see instead?
Expect no output and I get this:
AttributeError: 'Dot' object has no attribute 'attributes'

What version of the product are you using? On what operating system?
version: '1.0.2'
operating system: Linux

Please provide any additional information below.
I like turtles.  I like this project too.  Thanks

Original issue reported on code.google.com by [email protected] on 27 Aug 2008 at 6:40

Empty Output File

Hi Ero,

I am running pydot on Mac OS X 10.5.1 and am experiencing the empty output
file problem as described in
http://code.google.com/p/pydot/wiki/EmptyOutputFiles.

I added the path to graphviz to my path and the executables are being
found. This was verified via a debugger by stepping through the pydot
source code.

The source of my problem is the statement "data = stdout.read()" in
Dot.create() is not returning anything and thus "data" has no value.

I examined the temporary file referenced by stdout and verified that it
contains data.

I am running with the following versioned software:

  • pydot - 0.9.10
  • graphviz - 2.14
  • python - 2.5

Keith

Original issue reported on code.google.com by [email protected] on 18 Dec 2007 at 9:34

incorrect documentation: class Graph has option "graph_type" not "type"

The documentation for the class Graph repeatedly and incorrectly says there's 
an option "type" 
which can be digraph or graph. It should read "graph_type".

here's the current documentation, with the errors marked by *****:

class Graph(object, Common):

    """Class representing a graph in Graphviz's dot language.

    This class implements the methods to work on a representation
    of a graph in Graphviz's dot language.

    graph(graph_name='G', *****type='digraph', strict=False, suppress_disconnected=False, 
attribute=value, ...)

    graph_name:
        the graph's name
    *****type:
        can be 'graph' or 'digraph'

Original issue reported on code.google.com by [email protected] on 21 Jan 2008 at 5:44

pydot 1.0.4 does not parse graph node with "."(dot) in it

What steps will reproduce the problem?
1. in file test.dot, add a node with "." eg 2.3 [label="dot_node"] 
2. pydot.graph_from_dot_file(test.dot)
3. parse will fail

What is the expected output? What do you see instead?
node 2.3 will fail to parse. result in runtime exception

What version of the product are you using? On what operating system?
1.0.4 ubuntu 10.10

Possible fix:
In dot_parser.py, replace the line:
indentifier =  Word(alphanums + "_").setName("identifier")
with
indentifier =  Word(alphanums + "_" + ".").setName("identifier")

Original issue reported on code.google.com by [email protected] on 3 Mar 2011 at 3:36

Inconsitent parameter specification

This works:

pydot.Dot(rankdir="LR", overlap="False", graph_type='digraph', 
                        simplify=True)

This works not:

pydot.Dot(rankdir="LR", overlap=False, graph_type='digraph', 
                        simplify=True)

  File "file.py", line 374, in function
    dot.write_svg(directory+'/region_graph_%s.svg'%name, prog='neato')
  File "/var/lib/python-support/python2.5/pydot.py", line 1602, in <lambda>
    lambda path, f=frmt, prog=self.prog : self.write(path, format=f,
prog=prog))
  File "/var/lib/python-support/python2.5/pydot.py", line 1696, in write
    dot_fd.write(self.create(prog, format))
  File "/var/lib/python-support/python2.5/pydot.py", line 1740, in create
    self.write(tmp_name)
  File "/var/lib/python-support/python2.5/pydot.py", line 1694, in write
    dot_fd.write(self.to_string())
  File "/var/lib/python-support/python2.5/pydot.py", line 1472, in
to_string
    return ''.join(graph)
TypeError: sequence item 5: expected string, bool found


Why not allowing the natural data types?



Original issue reported on code.google.com by [email protected] on 17 Feb 2009 at 9:09

Dot parser doesn't allow for

What steps will reproduce the problem?
1. Create the following Dot file:
digraph {
    a -> b[label="hi", decorate];   
}
(The validity of this graph can be verified by running Dot on it.)

2. Run  pydot.dot_parser.graph_definition().parseFile('/path/to/file.dot')

PyDot complains, 'ParseException: Expected "}" (at char 24), (line:2, col:15).'

This issue appears to be caused by an erroneous assumption in the P_AttrList 
class that attributes always appear in name/value pairs. 

I'm using the latest release of PyDot on Scientific Linux with Python 2.5.1.

I have provided a patch to fix this problem; it merely prevents suppression of 
the '=' character in attribute lists and uses that in P_AttrList construction 
to determine which attributes have values and which do not.

Original issue reported on code.google.com by [email protected] on 2 Jul 2010 at 6:33

Attachments:

The set(<attr>, <value>) method dont work

What steps will reproduce the problem?
1. Try to simple use the set(<attr>, <value>) method

What is the expected output? What do you see instead?
The use of set method don't make effect in result.

What version of the product are you using? On what operating system?
Linux Slackware 12.0, GraphViz 2.16.1, pydot 1.0.2.

Please provide any additional information below.
You can contact me at [email protected] for more information.

Original issue reported on code.google.com by [email protected] on 29 Feb 2008 at 12:25

Non-string attribute (int) values break pydot

What steps will reproduce the problem?
1. for a dot node, try node.set_fontsize(8), without the string quotes
2. write the graph to an external file 
3. pydot will break in some to_string routine

What is the expected output? What do you see instead?
I expected to have the int converted to string

I used a python int value when setting stuff:
node.set_fontsize(8)
has to be
node.set_fontsize("8")
I couldn't point my finger directly on where to put a good fix

Original issue reported on code.google.com by [email protected] on 8 Apr 2008 at 11:09

Error while trying to run example pydot script on dkbza.org

What steps will reproduce the problem?
1. Copy the example pydot Python script into a file:

$ cat example.py
import pydot

edges=[(1,2), (1,3), (1,4), (3,4)]
g=pydot.graph_from_edges(edges)
g.write_jpeg('graph_from_edges_dot.jpg', prog='dot')

2. Run this script:

$ python example.py
Traceback (most recent call last):
  File "example.py", line 4, in ?
    g=pydot.graph_from_edges(edges)
  File "/d0/home/sramapra/personal/pydot-read-only/pydot.py", line 237, in
graph_from_edges
    e = Edge( node_prefix + edge[0], node_prefix + edge[1] )
TypeError: cannot concatenate 'str' and 'int' objects


What is the expected output? What do you see instead?

I should get a jpeg file that contains the graph.  I instead see the
traceback mentioned above.


What version of the product are you using? On what operating system?

$ uname -a
Linux arakkis 2.6.18.8-0.11-default #1 SMP Sat Oct 11 16:17:11 UTC 2008
x86_64 x86_64 x86_64 GNU/Linux

From pydot help:
VERSION
    1.0.2


Comments:

It appears that simply coercing the edge elements to strings will fix the
issue:
    e = Edge( node_prefix + str( edge[0] ), node_prefix + str( edge[1] ) )


Original issue reported on code.google.com by [email protected] on 17 Oct 2008 at 10:23

  • Merged into: #12

Graph.get_edge() has several bugs... more below

1: When adding an edge to a Graph via add_edge(Edge('foo', 'bar')) the key
value that ends up in the obj_dict['edges'] dictionary is not the ('foo',
'bar') pair, but rather the following: ('"foo"', '"bar"')

This causes me to have to do something silly when using the get_edge
function such as: Graph.get_edge('"%s"'%src, '"%s"'%dst) in order for it to
create ('"foo"', '"bar"') internally and actually find the edge i'm looking
for.

2: The documentation for get_edge() in incorrect.  It states:
"""Retrieved an edge from the graph.

        Given an edge's source and destination the corresponding
        Edge instance will be returned.

        If multiple edges exist with that source and destination,
        a list of Edge instances is returned.
        If only one edge exists, the instance is returned.
        None is returned otherwise.
        """

However in the code there is no place where None is actually returned:
snippet:
        if len(match)==1:
            return match[0]

        return match
should be:
        if len(match)==0:
            return None
        elif len(match)==1:
            return match[0]

        return match

3:  It would be nice if get_edge always returned an Edge or always returned
a list of Edges, but by being able to return both it requires users code to
check what it actually got in return.  If you simply returned a list of
Edges then it is easy for the user to check for None or len() of 1




Original issue reported on code.google.com by [email protected] on 24 Dec 2008 at 4:49

to_string causes OutOfMemory for large graphs

I have a graph from the python-graph library that I am rendering to a dot file. 
python-graph uses this library to interact with graphviz. The graph has 
approximately 1,200 nodes and 266,000 edges and runs out of memory on a 4 GB 
machine.

After some profiling, I found that it spent a majority of its time inside of 
pydot and memory usage started increasing dramatically in the to_string method.

Looking at the code, I found that pydot keeps all of the lines of the file in 
memory and then combines it into a single stream. With such a large file, it 
was keeping an absolutely huge list of strings in memory at the same time.

I think a solution to this is to optionally write the results to a file. This 
can be accomplished by having a "to_stream" method added to every class with a 
"to_string" method. Roughly it would be doing this for each "to_string" 
function.

Rename "to_string(self)" to "to_stream(self, graph)". Change all times when it 
does something like:

graph.append('text to write')

to

graph.write('text to write')

From there, you can implement "to_string" by using the builtin StringIO class.

from StringIO import StringIO

def to_string(self):
    try:
        buffer = StringIO()
        self.to_stream(buffer)
        return buffer.getvalue()
    finally:
        buffer.close()

I don't know if the close matters for StringIO. It frees the memory buffer 
(which you've already copied after using getvalue), but that buffer is probably 
freed by the destructor of StringIO.

You keep the old functionality and gain some additional functionality. Anybody 
who wants to use "to_stream" will have to manage whatever stream they want to 
send it to.

I can write this up and submit a patch later, but I won't have time until late 
tonight/tomorrow.

Original issue reported on code.google.com by [email protected] on 12 Apr 2011 at 8:12

Link to pyparsing on home page is wrong

What steps will reproduce the problem?

1. Click the link, it goes to a redirect page; the homepage for the project has 
moved

What is the expected output? What do you see instead?

Should just go to the new home page: http://pyparsing.wikispaces.com/


Original issue reported on code.google.com by [email protected] on 24 Nov 2010 at 2:12

get_node_list returns empty list on graphs with more than one node!

What steps will reproduce the problem?

edges=[('1','2'), ('1','3'), ('1','4'), ('3','4')] 
g=pydot.graph_from_edges(edges) 
nodes = g.get_node_list()
print len(nodes)

What is the expected output? What do you see instead?
Should see 4, get 0
Note that if you have a graph with only one node, you do get a one element list

What version of the product are you using? On what operating system?
1.0.2 on windows with python 2.5

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 9 May 2008 at 9:21

get_subgraphs() and get_subgraph() broken in 1.0.2

What steps will reproduce the problem?
1. Run the following (or similar) interactive Python session:

>>> import pydot
>>> g = pydot.Graph()
>>> s = pydot.Subgraph("foo")
>>> g.get_subgraphs()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/lib/python-support/python2.6/pydot.py", line 1345, in
get_subgraphs
    return get_subgraph_list()
NameError: global name 'get_subgraph_list' is not defined
>>> g.get_subgraph_list()
[]
>>> sgs = g.add_subgraph(s)
>>> g.get_subgraphs()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/lib/python-support/python2.6/pydot.py", line 1345, in
get_subgraphs
    return get_subgraph_list()
NameError: global name 'get_subgraph_list' is not defined
>>> g.get_subgraph_list()
[<pydot.Subgraph object at 0xa279d2c>]
>>> g.get_subgraph("foo")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/lib/python-support/python2.6/pydot.py", line 1330, in get_subgraph
    if self.obj_dict['subgraphs'].has_key( sgraph.get_name() ):
NameError: global name 'sgraph' is not defined


What is the expected output? What do you see instead?

  There are global name problems in the implementations of the
Graph.get_subgraphs() and Graph.get_subgraph(<name>) functions. This may
just be a case of having forgotten to include the "self" argument, which
has skipped by testing if the tests don't use subgraphs.

What version of the product are you using? On what operating system?

  I'm using the system package of pydot on Ubuntu 9.04 (Jaunty)

  >>> pydot.__version__
  '1.0.2'


Original issue reported on code.google.com by [email protected] on 16 May 2009 at 4:10

simplify bug

simplify=True does not work because class Edge does not provide an
appropriate __hash__ function, so that the test 

if self.obj_dict.get('simplify', False) and edge in edges_done:
                    continue

tests only for reference identify.

This patch helps:
836a835,836
>     def __hash__(self):
>         return hash(self.get_source()+self.get_destination())
1457,1458c1457,1458
<
<                 if self.obj_dict.get('simplify', False) and elm in
edges_done:

---
>
>                 if self.obj_dict.get('simplify', False) and edge in
edges_done:

Original issue reported on code.google.com by [email protected] on 17 Feb 2009 at 10:05

pydot crashes with character with accent

What steps will reproduce the problem?

import pydot
g = pydot.Dot()
g.add_node(pydot.Node("Anne-Cécile"))
g.add_edge(pydot.Edge(src='Anne-Cécile', dst='Anne-Marie'))
g.write('test.jpg', format='raw')
g.write_jpeg('test.jpg')

What is the expected output? What do you see instead?

>>> g.write_jpeg('test.jpg')
True

What do you see instead?

>>> g.write_jpeg('test.jpg')
Anne-Cécile [195, 169]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/site-packages/pydot.py", line 1603, in <lambda>
    lambda path, f=frmt, prog=self.prog : self.write(path, format=f,
prog=prog))
  File "/usr/lib/python2.5/site-packages/pydot.py", line 1697, in write
    dot_fd.write(self.create(prog, format))
  File "/usr/lib/python2.5/site-packages/pydot.py", line 1797, in create
    status, stderr_output) )
pydot.InvocationException: Program terminated with status: 6. stderr follows:
Error: /tmp/tmpVEABbQ:2: syntax error near line 2
context:  >>> Anne- <<< Cécile;


What version of the product are you using? On what operating system?
1.0.2 on Fedora 10 (also occurs in Rawhide)

Please provide any additional information below.

Originally filed here: https://bugzilla.redhat.com/show_bug.cgi?id=481540

Original issue reported on code.google.com by [email protected] on 3 Feb 2009 at 8:25

Quote in unicode html-labels

What steps will reproduce the problem?

# encoding: utf-8
import pydot
dot = pydot.Dot(charset='utf-8')
dot.add_node(pydot.Node('test',
    label=u'<<font color="red">Проба</font>>'.encode('utf-8')))
dot.write_png('test.png')

What is the expected output? What do you see instead?

expected:

digraph G {
        graph [charset="utf-8"];
        node [label="\N"];
        graph [bb="0,0,384,36"];
        test [label=<<font color="red">Проба</font>>, pos="192,18", width="5.33", height="0.50"];
}

now:

digraph G {
        graph [charset="utf-8"];
        node [label="\N"];
        graph [bb="0,0,384,36"];
        test [label="<<font color=\"red\">Проба</font>>", pos="192,18", width="5.33", height="0.50"];
}


What version of the product are you using? On what operating system?

pydot 1.0.25, Python 2.6.5, ubuntu 10.04

Original issue reported on code.google.com by [email protected] on 18 May 2011 at 9:47

get_subgraph function has a bug

What steps will reproduce the problem?
1. Call the get_subgraph function

What is the expected output? What do you see instead?
The expected output is a return type of Subgraph.  The current issue is a 
simple coding bug.  But I don't believe the implementation is correct.

What version of the product are you using? On what operating system?
1.02

Please provide any additional information below.

Here is the function fixed so that it doesn't fail.  As mentioned in the 
discussion group, I believe the subgraph functions as a whole need to be 
reviewed.  The subgraphs are being reconstructed incorrectly.

---------------------------------------------------------------------------
    def get_subgraph(self, name):

        match = []

        if self.obj_dict['subgraphs'].has_key( name ):

            sgraphs_obj_dict = self.obj_dict['subgraphs'].get( name )

            for obj_dict_list in sgraphs_obj_dict:
                match = [ Subgraph( obj_dict = obj_d ) for obj_d in 
obj_dict_list ]

        if len(match)==1:
            return match[0]

        return match
---------------------------------------------------------------------------


Original issue reported on code.google.com by [email protected] on 7 Jul 2009 at 1:42

  • Merged into: #30

find_graphviz on OS X

Hi Ero,

Thanks for maintaining PyDot, it's very handy. PyDot has trouble finding
the graphviz executables on my machine (a Mac). The Mac version of GraphViz
tucks the executables into an application, so they don't usually make it
onto the path. They get put in

prefix/Graphviz.app/Contents/MacOS/ ,

where 'prefix' is usually but not necessarily '/Applications'. I don't know
if there's anything you can do about this, but thought you might like to know.


Original issue reported on code.google.com by [email protected] on 14 Aug 2007 at 7:01

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.