All Projects → pydot → Pydot

pydot / Pydot

Licence: mit
Python interface to Graphviz's Dot language

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pydot

Diagrams
🎨 Diagram as Code for prototyping cloud system architectures
Stars: ✭ 15,756 (+2941.7%)
Mutual labels:  hacktoberfest, graphviz
Asciidoctor Kroki
Asciidoctor.js extension to convert diagrams to images using Kroki!
Stars: ✭ 55 (-89.38%)
Mutual labels:  hacktoberfest, graphviz
Kroki
Creates diagrams from textual descriptions!
Stars: ✭ 774 (+49.42%)
Mutual labels:  hacktoberfest, graphviz
Phpdocumentor
Documentation Generator for PHP
Stars: ✭ 3,341 (+544.98%)
Mutual labels:  hacktoberfest, graphviz
Devjoke
#DevJoke. Submit a PR if you know a good dev joke.
Stars: ✭ 516 (-0.39%)
Mutual labels:  hacktoberfest
Topydo
A powerful todo list application for the console, using the todo.txt format.
Stars: ✭ 511 (-1.35%)
Mutual labels:  hacktoberfest
Yopass
Secure sharing for secrets, passwords and files
Stars: ✭ 511 (-1.35%)
Mutual labels:  hacktoberfest
Aws Security Viz
Visualize your aws security groups.
Stars: ✭ 511 (-1.35%)
Mutual labels:  graphviz
Algorithmic Pseudocode
This repository contains the pseudocode(pdf) of various algorithms and data structures necessary for Interview Preparation and Competitive Coding
Stars: ✭ 519 (+0.19%)
Mutual labels:  hacktoberfest
Space Nerds In Space
Multi-player spaceship bridge simulator. Captain your starship through adventures with your friends. See https://smcameron.github.io/space-nerds-in-space
Stars: ✭ 516 (-0.39%)
Mutual labels:  hacktoberfest
Messagekit
A community-driven replacement for JSQMessagesViewController
Stars: ✭ 5,036 (+872.2%)
Mutual labels:  hacktoberfest
Hackers
Hackers is an elegant iOS app for reading Hacker News written in Swift.
Stars: ✭ 513 (-0.97%)
Mutual labels:  hacktoberfest
Guide
The official guide for discord.js, created and maintained by core members of its community
Stars: ✭ 512 (-1.16%)
Mutual labels:  hacktoberfest
Obs Web
OBS-web - the easiest way to control OBS remotely
Stars: ✭ 512 (-1.16%)
Mutual labels:  hacktoberfest
Teresa
Open source tool to deploy apps to Kubernetes clusters
Stars: ✭ 517 (-0.19%)
Mutual labels:  hacktoberfest
Hacktoberfest
Hacktoberfest - App to manage the annual open source challenge.
Stars: ✭ 512 (-1.16%)
Mutual labels:  hacktoberfest
Octolinker
OctoLinker — Links together, what belongs together
Stars: ✭ 4,853 (+836.87%)
Mutual labels:  hacktoberfest
Indy Sdk
Everything needed to build applications that interact with an Indy distributed identity ledger.
Stars: ✭ 516 (-0.39%)
Mutual labels:  hacktoberfest
Telethon
Pure Python 3 MTProto API Telegram client library, for bots too!
Stars: ✭ 5,805 (+1020.66%)
Mutual labels:  hacktoberfest
Imagesharp
📷 A modern, cross-platform, 2D Graphics library for .NET
Stars: ✭ 5,186 (+901.16%)
Mutual labels:  hacktoberfest

Build Status PyPI

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.

License

Distributed under an MIT license.

Contacts

Maintainers:

Original author: Ero Carrera [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].