我想知道如何绘制这样的矩阵:
我知道如何绘制一个简单的矩阵:
\documentclass[journal]{IEEEtran}
\usepackage[pdftex]{graphicx}
\usepackage{tikz}
\usetikzlibrary{matrix, calc}
\begin{document}
\begin{tikzpicture}
\matrix (input) [matrix of nodes,
nodes={rectangle, draw=white, minimum size=.8cm}] at (0,0)
{
|[fill=black]| & |[fill=black!20]| & |[fill=black!50]| \\
|[fill=black!50]| & |[fill=black!50]| & |[fill=black!20]| \\
|[fill=black!20]| & |[fill=black!20]| & |[fill=black]| \\
};
\node [draw,below=8pt] at (input.south) {Sample};
\end{tikzpicture}
\end{document}
但不知道如何改变它才能达到我想要的效果。
谢谢。
答案1
利用图形的旋转对称性来回答一个问题:
\begin{tikzpicture}[thick, scale=.35]
\draw[densely dotted, gray, shift={(-4.5,-4.5)}] (0,0) grid +(9,9);
\draw (-4.5,-4.5) rectangle (4.5,4.5);
\node {x};
\foreach[count=\i] \a in {0,1,2,3} {
\begin{scope}[rotate={90*\a}]
\draw (4.5,3.5) -| ++(-1,-1) -| ++(-1,-1) -| ++(-1,-1) -- ++(-6,0);
\path let \n1={int(2*\i-1)}, \n2={int(2*\i)} in (3,1) node{\n1} (2,3) node{\n2};
\end{scope}
}
\end{tikzpicture}
答案2
只是玩玩(没有tikz
),建立\Sv
(垂直实线)、\Dv
(垂直虚线)、\Sh
(水平实线)、\Dh
(水平虚线)的堆叠层。垂直线上的可选参数提供以下行的文本
怪癖:\Sd
由于我构建事物的方式,需要在图表的右上角有一个(实心点)。并且\intersect
可能需要定义为{.}
如果将\dashfill
交叉点留空。
\documentclass{article}
\def\LN{2ex}
\def\WD{1pt}
\usepackage{stackengine,xcolor,graphicx}
\def\intersect{}% might need it as {.}
\def\dashfill{\cleaders\hbox to 1.43pt{.}\hfill}
\newcommand\dashline[1]{\textcolor{black!50}{\hbox to #1{\dashfill\hfil}}}
\newcommand\Sh{\rule{\LN}{\WD}}
\newcommand\Sd{\rule{\WD}{\WD}}
\newcommand\Sv[1][]{%
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