Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples of Graph/Network rendering #89

Closed
1 of 2 tasks
jbednar opened this issue Oct 8, 2018 · 5 comments
Closed
1 of 2 tasks

Add examples of Graph/Network rendering #89

jbednar opened this issue Oct 8, 2018 · 5 comments
Labels
good first issue Good for newcomers type: docs Related to the Panel documentation and examples

Comments

@jbednar
Copy link
Member

jbednar commented Oct 8, 2018

As of PRs #85 and #88, dot-based graph plots are now supported in Panel, either as SVG representations of GraphViz Graph/DiGraph objects, or as PNG representations of NetworkX objects created by nxpd.draw():

from graphviz import Graph
hw = Graph('hello', format='svg')
hw.edge('Hello', 'World')

import networkx as nx, nxpd
G = nx.cycle_graph(4, create_using=nx.DiGraph())
d = nxpd.draw(G, show='ipynb')

import panel as pn
pn.Row(hw, "Text", d, "Text")

image

Remaining issues:

  • Spacing for these objects is not currently automatically determined
  • It would be nice to provide graph examples in the User Guide
@philippjfr
Copy link
Member

philippjfr commented May 17, 2019

nxpd seems like a pretty niche library to consider here. I'd just draw the networkx graph using pygraphviz:

from graphviz import Graph
hw = Graph('hello', format='svg')
hw.edge('Hello', 'World')

import networkx as nx
G = nx.complete_graph(5)
A = nx.nx_agraph.to_agraph(G)

import panel as pn
pn.Row(hw, "Text", A.draw(prog='dot', format='svg').decode('utf-8'), "Text")

@jbednar
Copy link
Member Author

jbednar commented May 17, 2019

A.draw?

@philippjfr
Copy link
Member

Fixed.

@philippjfr philippjfr added the type: docs Related to the Panel documentation and examples label Jul 25, 2019
@philippjfr philippjfr changed the title Graph/network plotting support Add examples of Graph/Network rendering Jul 25, 2019
@kcpevey kcpevey added the good first issue Good for newcomers label Aug 3, 2020
@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Sep 12, 2021

Using Panel 0.12.1 The above example does not work for me. The output of A.draw needs to be clean by removing things in front of <svg.

This works

from graphviz import Graph
import panel as pn
import networkx as nx

graphviz_graph = Graph('hello', format='svg')
graphviz_graph.edge('Hello', 'World')

graph = nx.complete_graph(5)
pyviz_graph = nx.nx_agraph.to_agraph(graph)

def clean_svg(svg):
    svg.find("<svg")
    svg_start = svg.find("<svg")
    return svg[svg_start:]

networkx_svg = clean_svg(pyviz_graph.draw(prog='dot', format='svg').decode('utf-8'))

pn.Row(
    graphviz_graph,
    "Text",
    networkx_svg,
    "Text").servable()

@MarcSkovMadsen
Copy link
Collaborator

#2732 Should close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers type: docs Related to the Panel documentation and examples
Projects
None yet
Development

No branches or pull requests

4 participants