帮助 Tikz 着色和绘制箭头

帮助 Tikz 着色和绘制箭头

我目前正在尝试用 Tikz 猜测这张图片(https://postimg.cc/qhZdj8cD)。不幸的是,我的解决方案看起来还不够好。我可以改变什么让它看起来更像图片?我关心的是颜色填充和轴上的箭头。这是我目前的代码。提前致谢

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \draw (-1,0) -- (45.4,0);
    \draw (0,0) rectangle ++(2,2);
    \draw (2,0) rectangle ++(2,2);
    \draw (4,0) rectangle ++(2,2);
    \draw (6,4,0) rectangle ++(2,2);
    \draw (8.4,0) rectangle ++(2,2);
    \draw (10.4,0) rectangle ++(2,2);
    \draw (12.8,0) rectangle ++(2,2);
    \draw (14.8,0) rectangle ++(2,2);
    \draw (16.8,0) rectangle ++(2,2);
    \draw (19.2,0) rectangle ++(2,2);
    \draw (21.2,0) rectangle ++(2,2);
    \draw (23.2,0) rectangle ++(2,2);
    \draw (25.6,0) rectangle ++(2,2);
    \draw (27.6,0) rectangle ++(2,2);
    \draw (29.6,0) rectangle ++(2,2);
    \draw (32,0) rectangle ++(2,2);
    \draw (34,0) rectangle ++(2,2);
    \draw (36,0) rectangle ++(2,2);
    \draw (38,4,0) rectangle ++(2,2);
    \draw (40.4,0) rectangle ++(2,2);
    \draw (42.4,0) rectangle ++(2,2);
    \draw (6.2,-1) -- ++(0,2);
    \draw (12.6,-1) -- ++(0,2);
    \draw (19,-1) -- ++(0,2);
    \draw (25.4,-1) -- ++(0,2);
    \draw (31.8,-1) -- ++(0,2);
    \draw (38.2,-1) -- ++(0,2);
    \node at (3,-0.5){day 1};
    \node at (9,4,-0.5){day 2};
    \node at (15.8,-0.5){day 3};
    \node at (22.2,-0.5){day 4};
    \node at (28.6,-0.5){day 5};
    \node at (35,-0.5){day 6};
    \node at (41.4,-0.5){day 7};
\end{tikzpicture}
\end{document}

答案1

就像这样(3 天......):

在此处输入图片描述

代码:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}
        \fill[blue] (.4,0) rectangle (1.4,1);
        \fill[red] (1.4,0) rectangle (2.4,1);
        \fill[cyan] (2.4,0) rectangle (3.4,1);
        \draw (.2,-.5)--(.2,.5);
        \draw (3.6,-.5)--(3.6,.5);
        \node at (1.9,-.3) () {\bfseries Day 1};
        
        \fill[blue] (3.8,0) rectangle (4.8,1);
        \fill[red] (4.8,0) rectangle (5.8,1);
        \fill[cyan] (4.8,1) rectangle (5.8,2);
        \draw (.2,-.5)--(.2,.5);
        \draw (3.6,-.5)--(3.6,.5);
        \node at (5.25,-.3) () {\bfseries Day 2};
        
        \fill[blue] (7,0) rectangle (8,1);
        \fill[red] (9,0) rectangle (10,1);
        \fill[cyan] (9,1) rectangle (10,2);
        \draw (10.2,-.5)--(10.2,.5);
        \draw (6.8,-.5)--(6.8,.5);
        \node at (8.5,-.3) () {\bfseries Day 3};
        \draw[-latex,line width=2pt] (0,0)--(10.7,0);
    \end{tikzpicture}
\end{document}

编辑传奇

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
    \begin{tikzpicture}
        \fill[blue] (.4,0) rectangle (1.4,1);
        \fill[red] (1.4,0) rectangle (2.4,1);
        \fill[cyan] (2.4,0) rectangle (3.4,1);
        \draw (.2,-.5)--(.2,.5);
        \draw (3.6,-.5)--(3.6,.5);
        \node at (1.9,-.3) () {\bfseries Day 1};
        
        \fill[blue] (3.8,0) rectangle (4.8,1);
        \fill[red] (4.8,0) rectangle (5.8,1);
        \fill[cyan] (4.8,1) rectangle (5.8,2);
        \draw (.2,-.5)--(.2,.5);
        \draw (3.6,-.5)--(3.6,.5);
        \node at (5.25,-.3) () {\bfseries Day 2};
        
        \fill[blue] (7,0) rectangle (8,1);
        \fill[red] (9,0) rectangle (10,1);
        \fill[cyan] (9,1) rectangle (10,2);
        \draw (10.2,-.5)--(10.2,.5);
        \draw (6.8,-.5)--(6.8,.5);
        \node at (8.5,-.3) () {\bfseries Day 3};
        \draw[-latex,line width=2pt] (0,0)--(10.7,0);
        
        \fill[blue] (.5,-1.5) rectangle (1,-1);
        \node at (1.5,-1.25) () {One};
        
        \fill[red] (3,-1.5) rectangle (3.5,-1);
        \node at (4,-1.25) () {Two};
        
        \fill[cyan] (5.5,-1.5) rectangle (6,-1);
        \node at (6.5,-1.25) () {Three};
    \end{tikzpicture}
\end{document}

新输出:

在此处输入图片描述

答案2

有节点在链中。前三天:

在此处输入图片描述

\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                positioning}
                
\begin{document}
    \begin{tikzpicture}[
node distance = 0mm and 1mm,
  start chain = A going right,
     N/.style = {draw, fill=#1!30, minimum size=5mm, outer sep=0pt,
                 node contents={},on chain=A}
                        ]
\node[N=green];                     % A-1
\node[N=red];
\node[N=blue];
%
\node[N=green];                     % A-4
\node[N=blue];
%
\node[N=green,right=7mm of A-5];    % A-6
\node[N=blue, right=7mm of A-6];    % A-7
% nodes above
\node[N=red, above=of A-5];
\node[N=red, above=of A-7];
% arrow
\draw[-Straight Barb, semithick]
    ([xshift=-4mm] A-1.south west) -- ([xshift=4mm] A-7.south east);
% tick
    \foreach \x [count=\i] in {1,4,6}
\draw ([xshift=-0.5mm] A-\x.west) -- ++ (0,-0.8)  coordinate[yshift=2mm] (d\i);
\draw ([xshift= 0.5mm] A-7.east)  -- ++ (0,-0.8)  coordinate[yshift=2mm] (d4);
% days
\path   (d1) -- node {Day 1} (d2)
             -- node {Day 2} (d3)
             -- node {Day 3} (d4);
\end{tikzpicture}
\end{document}

相关内容