Graphics, Figures & TablesGetting an image of a graph using an adjacency matrix

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
DivineBoss
Posts: 1
Joined: Wed Dec 07, 2022 12:00 pm

Getting an image of a graph using an adjacency matrix

Post by DivineBoss »

Good afternoon, I ran into the problem of creating an image of a graph.

Available data - generated adjacency matrices of graphs

It is required to output graph images based on these adjacency matrices

All the solutions I have seen require a separate array of coordinates of each vertex, for this I need to somehow find out the topology of the graph, which is quite difficult.

Is there an easier way to display the graph image?

It should turn out something like this (1st attachment)

I also found the following code, but the problem is that it can only build regular polygons and to build something more complicated, you need to know the topology of the graph

\def\adjancymatrix{%
{
{0,0,0,0,1},%
{0,0,0,0,1},%
{0,0,0,0,1},%
{0,0,0,0,1},%
{1,1,1,1,0}}}
\let\mymatrixcontent\empty
\def\mymatrixcontent{|[draw=none]|\& 1 \& 2 \& 3 \& 4 \& 5\\}
\begin{scope}[local bounding box=middle,xshift=5cm]
\foreach \X in {1,...,5}
{\node[Bullet,label=90+72-\X*72:{$_\X$}] (E\X) at (90-\X*72:2) {} ;}
\foreach \X in {1,...,5}
{\begingroup\edef\x{\endgroup
\noexpand\gappto\noexpand\mymatrixcontent{\X }}\x
\foreach \Y in {1,...,5}
{\pgfmathtruncatemacro{\itest}{\adjancymatrix[\X-1][\Y-1]}
\ifnum\itest=1
\draw (E\X) -- (E\Y);
\begingroup\edef\x{\endgroup
\noexpand\gappto\noexpand\mymatrixcontent{\& 1 }}\x
\else
\begingroup\edef\x{\endgroup
\noexpand\gappto\noexpand\mymatrixcontent{ \&}}\x
\fi
}
\gappto\mymatrixcontent{\\}
}
\end{scope}
\matrix (midmat) [below=of middle,adjacency matrix]{
\mymatrixcontent
};
Attachments
Снимок экрана 2022-12-07 130458.jpg
Снимок экрана 2022-12-07 130458.jpg (5.15 KiB) Viewed 2344 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply