曲线图

演示如何使用javascript infovis toolkit(jit)json export的示例

请参阅http://the jit.org上的JIT文档和示例。

../../_images/sphx_glr_plot_rgraph_001.png

出:

[
    {
        "id": "solo",
        "data": {},
        "name": "solo"
    },
    {
        "id": 3,
        "data": {},
        "adjacencies": [
            {
                "data": {
                    "type": "extra special"
                },
                "nodeTo": "two"
            }
        ],
        "name": 3
    },
    {
        "id": "one",
        "data": {
            "type": "normal"
        },
        "adjacencies": [
            {
                "data": {},
                "nodeTo": "two"
            }
        ],
        "name": "one"
    },
    {
        "id": "two",
        "data": {
            "type": "special"
        },
        "adjacencies": [
            {
                "data": {
                    "type": "extra special"
                },
                "nodeTo": 3
            },
            {
                "data": {},
                "nodeTo": "one"
            }
        ],
        "name": "two"
    }
]
Nodes: [('solo', {}), (3, {}), ('one', {'type': 'normal'}), ('two', {'type': 'special'})]
Edges: [(3, 'two', {'type': 'extra special'}), ('one', 'two', {})]

__author__ = """Ollie Glass (ollieglaskovik@gmail.com)"""

import json

import matplotlib.pyplot as plt
import networkx as nx
from networkx.readwrite.json_graph import jit_data, jit_graph

# add some nodes to a graph
G = nx.Graph()

G.add_node("one", type="normal")
G.add_node("two", type="special")
G.add_node("solo")

# add edges
G.add_edge("one", "two")
G.add_edge("two", 3, type="extra special")

# convert to JIT JSON
jit_json = jit_data(G, indent=4)
print(jit_json)

X = jit_graph(json.loads(jit_json))
print("Nodes: %s" % list(X.nodes(data=True)))
print("Edges: %s" % list(X.edges(data=True)))

nx.draw(G, with_labels=True)
plt.show()

Total running time of the script: ( 0 minutes 0.201 seconds)

Gallery generated by Sphinx-Gallery