วิธีใส่คำอธิบายประกอบเมทริกซ์แบบสุ่มใน TikZ
ฉันมีสิ่งต่อไปนี้ซึ่งสร้างภาพเมทริกซ์แบบสุ่ม (ตัวอย่างแรก) แต่ฉันคิดไม่ออกว่าจะทำอย่างไร:
แก้ไขรูปร่างของเซลล์ที่ด้านบนและด้านขวา
เพิ่มโทนสี (สีน้ำเงินในตัวอย่างที่สอง)
ทำให้เป็นชิ้นที่ระบุไว้ (ตัวอย่างที่สอง)
\begin{figure}[p] \begin{tikzpicture}[scale=1] \foreach \y in {0.1,0.2,...,.9} { \foreach \x in {0.1,0.2,...,.9} { \pgfmathparse{0.9*rnd+0.3} \definecolor{MyColor}{rgb}{\pgfmathresult,\pgfmathresult,\pgfmathresult} \node[fill=MyColor,inner sep=0.1cm,outer sep=0pt,anchor=center] at (\x,\y) {}; } } \end{tikzpicture} \end{figure}
เอาต์พุต (ตัวอย่างที่ 1):

ฉันสาธิตขั้นตอนเหล่านี้ในตัวอย่างที่ 2 แต่ฉันสามารถทำให้มันใช้งานได้จากไฟล์ pdf ที่สร้างไว้ล่วงหน้าเท่านั้น:
\begin{tikzpicture}
\node[inner sep=0pt] (tumor1to4) at (0,0) {\includegraphics[trim=0 400 400 0,clip,width=20ex,height=20ex]{Plots/Clipart/heatmap.pdf}};
\node[right=1ex of tumor1to4,font=\fontsize{20}{0}\selectfont, thick] (el1) {...};
\node[inner sep=0pt, right= 0.5ex of el1] (tumorp) {\includegraphics[trim=0 400 475 0,clip,height=20ex]{Plots/Clipart/heatmap.pdf}};
\node[right=0.5ex of tumorp,font=\fontsize{20}{0}\selectfont, thick] (el2) {...};
\node[inner sep=0pt, right= 0.5ex of el2] (tumorP) {\includegraphics[trim=475 400 0 0,clip,height=20ex]{Plots/Clipart/heatmap.pdf}};
\node[below=3ex of tumor1to4,font=\fontsize{20}{0}\selectfont, thick, rotate=90] (el3) {...};
\node[inner sep=0pt, below =5.5ex of tumor1to4] (tumorK) {\includegraphics[trim=0 300 400 178,clip,width=20ex]{Plots/Clipart/heatmap.pdf}};
\node[right=1ex of tumorK,font=\fontsize{20}{0}\selectfont, thick] (el5) {...};
\node[inner sep=0pt, right= 0.5ex of el5] (tumorKp) {\includegraphics[trim=0 300 475 178,clip,width=5ex]{Plots/Clipart/heatmap.pdf}};
\node[right=0.5ex of tumorKp,font=\fontsize{20}{0}\selectfont, thick] (el6) {...};
\node[inner sep=0pt, right= 0.5ex of el6] (tumorKP) {\includegraphics[trim=475 300 0 178,clip,height=5ex]{Plots/Clipart/heatmap.pdf}};
\node[draw=red,size=3pt,rectangle,fit=(tumorp) (tumorKp)] {};
\end{tikzpicture}
เอาต์พุต (ตัวอย่างที่ 2):

ตอนนี้คำถามคือฉันจะใส่คำอธิบายประกอบตัวอย่างที่ 1 ในตัวอย่างที่ 2 ได้อย่างไร
คำตอบ
ประการแรกinner sep=0.1cm
ทุกโหนดมีขนาด 0.2 ซม. x 0.2 ซม. ทำให้เกิดปัญหารูปร่างของเซลล์ด้านบนและด้านขวา
ที่นี่ฉันใช้inner sep=0pt, minimum size=1cm
แทน คุณอาจเลือกสีพื้นฐานอื่นและช่วงสีแบบสุ่มแทนblue
และ[-75, 75]
ตามลำดับ
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[inner sep=0pt, minimum size=1cm]
\foreach \y in {1, ..., 9} {
% add vertical shift and dots
\ifnum\y=2\relax
\tikzset{yshift=-1cm}
\else
\ifnum\y=1\relax
\path node at (5, \y+1) {\huge$\vdots$};
\fi
\fi
\foreach \x in {1, ..., 9} {
% add horizontal shift and dots
\ifnum\x<8\relax
\else
\tikzset{xshift=1cm*(\x-7)}
\ifnum\y=1\relax
\path node at (\x-1, 5) {\huge\ldots}
node at (\x-1, 1) {\huge\ldots};
\fi
\fi
% get random color
\pgfmathparse{int(150*rnd-75)} % [-75, 75]
% color range: blue!75!white .. blue!100 .. blue!75!black
\ifnum\pgfmathresult>0\relax
\colorlet{MyColor}{black!\pgfmathresult!blue}
\else
\edef\pgfmathresult{-\pgfmathresult}
\colorlet{MyColor}{white!\pgfmathresult!blue}
\fi
% draw filled square
\node[fill=MyColor] at (\x,\y) {};
}
}
\end{tikzpicture}
\end{document}
