【问题标题】:Is there a way to embed code that uses python's Networkx package for graphs on a website so that the output can be displayed directly on the website?有没有办法在网站上嵌入使用 python 的 Networkx 包的图形代码,以便输出可以直接显示在网站上?
【发布时间】:2020-06-19 16:19:57
【问题描述】:

我正在设计一个关于小世界网络研究项目的网站。我们正在编写代码来可视化不同的图形指标。 Python 有一个很棒的图包 networkX,所以我们所有的代码都在 python 中。例如,这段代码绘制了一个图形,并显示了图形的一些特征。

import sys

import matplotlib.pyplot as plt
from networkx import nx

G = nx.lollipop_graph(8, 3)
nx.draw(G)
plt.show()

print("radius: %d" % nx.radius(G))
print("diameter: %d" % nx.diameter(G))
print("eccentricity: %s" % nx.eccentricity(G))
print("center: %s" % nx.center(G))
print("periphery: %s" % nx.periphery(G))
print("density: %s" % nx.density(G))

a plot of a lollipop graph(8,3)

我的目标是以某种方式在网站上包含和运行这样的 sn-ps 代码,以便当用户输入他们想要查看的图表类型时,这些图可以显示在我的网站上。有没有办法让我在 HTML 中嵌入 python 代码?

【问题讨论】:

  • 请展示您到目前为止所做的尝试。请阅读how to ask
  • @above_c_level 我试图让问题更具体。我尝试使用 trinket 嵌入代码,但是 trinket 没有 networkX 包。

标签: python html networkx web-site-project


【解决方案1】:

你可以用一个小饰品来运行它:

<html>
     <head>
      <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
      <title>PY game</title>
     </head>

     <body>
      <iframe src="https://trinket.io/embed/python/b7ae19a9ca? 
      outputOnly=true&runOption=run&start=result" width="100%" height="100%" 
      frameborder="0" marginwidth="0" marginheight="0" allowfullscreen></iframe>
     </body>

    </html>

【讨论】:

  • 我没有投反对票,但如果您阅读 How to Ask 页面,您会发现该问题不符合社区准则。因此,不鼓励提供答案(这会防止问题被删除)——网站上有大量糟糕的问题会使每个人都很难找到高质量的问题/答案(因为噪声比高)
猜你喜欢
  • 1970-01-01
  • 2021-10-20
  • 2019-04-03
  • 2023-01-17
  • 1970-01-01
  • 2023-03-06
  • 1970-01-01
  • 2010-12-23
  • 1970-01-01
相关资源
最近更新 更多