如何自动要求 tikz 生成坐标并根据邻接矩阵绘制图形

如何自动要求 tikz 生成坐标并根据邻接矩阵绘制图形

我对以下内容感到好奇:

我有一个 36 阶图的邻接矩阵。 它由以下公式给出

[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0],
[1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0],
[1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0],
[1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1],
[1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0],
[1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1],
[1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0],
[1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0],
[1,0,1,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,0,0],
[1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1],
[1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0],
[1,1,1,1,1,1,1,1,1,1,1,1,0,1,1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,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0],
[1,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1],
[1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1],
[1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0],
[1,1,0,1,1,0,1,1,0,1,0,0,1,1,0,1,1,0,1,1,0,0,1,0,1,1,0,1,1,0,1,1,0,1,1,0],
[1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0],
[1,1,1,1,0,1,0,1,1,0,1,1,1,0,0,1,1,1,1,0,0,1,1,1,0,1,1,0,1,0,1,1,1,1,0,1],
[1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0],

如果我在 SageMath 中绘制图表,我会得到以下图表

在此处输入图片描述

我想知道是否可以在 Tikz 中绘制图形,而无需从邻接矩阵自动指定坐标。

手动指定坐标会非常困难。我试过一次,但没有成功。看起来很麻烦。

有人可以帮忙根据邻接矩阵绘制图形吗?

以下问题没有回答我的问题如何根据邻接矩阵和顶点坐标绘制图形?

因为我没有指定坐标。我希望 TeX 像 SageMath 一样自动修复坐标。

是否可以??

答案1

听起来你正在尝试做一件我花了一段时间才搞定的事情:将 SAGE 结果推送到 LaTeX 中,获得更好的输出。我的答案这里对康托函数进行同样的操作,绘制素数3D 图, 和这里. 在网站上搜索sagetex更多示例。上面 js bibra 提到的链接展示了一些如何使用图表来实现这一点,但你需要深入挖掘一下。这里还有一些解释。

\documentclass[border={2mm 2mm 8mm 8mm}]{standalone}
\usepackage{sagetex,xcolor,tikz,tkz-graph,tkz-berge}
\begin{document}
\begin{sagesilent}
M = Matrix([(0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
(1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0),
(1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0),
(1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0),
(1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1),
(1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0),
(1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1),
(1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0),
(1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0),
(1,0,1,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,0,0),
(1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1),
(1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,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0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0),
(1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0),
(1,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0),
(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1),
(1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0),
(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1),
(1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0),
(1,1,0,1,1,0,1,1,0,1,0,0,1,1,0,1,1,0,1,1,0,0,1,0,1,1,0,1,1,0,1,1,0,1,1,0),
(1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0),
(1,1,1,1,0,1,0,1,1,0,1,1,1,0,0,1,1,1,1,0,0,1,1,1,0,1,1,0,1,0,1,1,1,1,0,1),
(1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0)])
g = Graph(M)
g.set_pos(g.layout_circular())
g.set_latex_options(graphic_size=(20,20))
\end{sagesilent}
\begin{tikzpicture}[node distance = 10mm and 10mm]
\tikzset{EdgeStyle/.append style = {color = blue!60, line width=1pt}}
\sage{g}
\end{tikzpicture}
\end{document}

Cocalc 的输出如下所示: 在此处输入图片描述

需要提及的一些事项:

  1. Sage 可以帮您完成定位。文档中介绍了这一点这里。查看绘图选项,然后layout。我选择g.set_pos(g.layout_circular())了圆形布局。
  2. 我已经用 设置了图形的大小(这将影响圆的大小)g.set_latex_options(graphic_size=(20,20))。您可以根据自己的需要尝试不同的大小。
  3. 请注意,Sage 列出的顶点从顶点 0 开始。在另一篇帖子您似乎在问类似的问题,但您的顶点从 1 开始。您可以先在 Sage 中重新标记顶点。添加行g.relabel(lambda x: x+1)sagesilent顶点将从 1 变为 36,如下所示:

在此处输入图片描述

一般来说,在 中设置图表会有所帮助sagesilent,您可以在 中调整一些设置tikz。线条\tikzset{EdgeStyle/.append style = {color = blue!60, line width=1pt}}设置线条的颜色和宽度。但是,有时您只需要摆弄图表的哪些部分应该在 Sage 中设置,哪些部分应该在 LaTeX 中设置。查看其他帖子,例如这里这里。请注意,如果图表有名称,您也可以使用它。Sage 可识别各种图表给出. 给出了使用 Sage 绘制图表的 LaTeX 选项这里

相关内容