使用 Tikz 绘制彩色立方体/平面?

使用 Tikz 绘制彩色立方体/平面?

我正在尝试在 TikZ 中重现下图。但我无法让它工作 :( 在此处输入图片描述 是否有一个包可以帮助并轻松绘制它。

答案1

您的版本几乎已经完成,恭喜。我使用了您的一些作品,并添加了一些我自己的作品。

\documentclass[tikz,border=3.141592mm]{standalone}
\usetikzlibrary{arrows.meta}
\usepackage{newtxtext,newtxmath}

\newcommand{\defclr}{
    \pgfmathsetmacro\wavelen{\wavemax-(\wavemax-\wavemin)*\i/\t}
    \definecolor{clr}{wave}{\wavelen}}

\begin{document}

    \begin{tikzpicture}[
        >=Stealth,
        every node/.style={scale=1.5},
        x={(0.19 cm,0.16 cm)},
        y={(0 cm,1 cm)},
        z={(1 cm,0 cm)}
        ]
        
        \draw [->] (-1,0,0) -- (40,0,0) node [at end, above] {$\lambda$};
        \draw [->] (0,-1,0) -- (0,6,0) node [at end, left] {$y$};
        \draw [->] (0,0,-1) -- (0,0,20) node [at end, above] {$z$};
        
        \def\t{18} \def\op{0.6}
        \def\wavemax{420} \def\wavemin{650} % obvious, isn't it?
        \def\l{2.5} %length of the squares
        \def\a{1} \def\b{7} \def\c{13} % z pos of the square stacks
        
        \foreach \i in {0,9,...,\t}
            {
            \defclr
            \fill[clr,opacity=\op] (\t-\i+3,0,\a) rectangle ++ (0,\l,\l);
            }       
        
        \foreach \i in {0,3,...,\t}
            {
            \defclr
            \fill[clr,opacity=\op] (\t-\i+3,0,\b) rectangle ++ (0,\l,\l);
            }
        
        \foreach \i in {0,0.5,...,\t}
            {
            \defclr
            \fill[clr,opacity=\op] (\t-\i+3,0,\c) rectangle ++ (0,\l,\l);
            }   
        
        \node[below=15pt] at (3,0,\a+.5*\l) {RGB};
        \node[below=15pt] at (3,0,\b+.5*\l) {MSI};
        \node[below=15pt] at (3,0,\c+.5*\l) {HSI};

    \end{tikzpicture}
    
\end{document}

波长

编辑

我搜索了一种方法,为方块添加漂亮的纹理,就像原始图片中那样,但找不到任何方法(欢迎在评论中提出任何建议)。但我认为添加一些模糊阴影来给这张图片增添一点活力是个好主意。所以这是第二个版本,有一些调整和阴影。

\documentclass[tikz,border=3.141592mm]{standalone}
\usetikzlibrary{arrows.meta,shadows.blur}
\usepackage{newtxtext,newtxmath}

\newcommand{\defclr}{
    \pgfmathsetmacro\wavelen{\waveback-(\waveback-\wavefront)*\i/\t}
    \definecolor{clr}{wave}{\wavelen}}

\tikzset{myshadow/.style={blur shadow={shadow blur steps=50,shadow blur extra rounding=3pt,shadow xshift=5pt,shadow yshift=-5pt, shadow blur radius=3pt,shadow opacity=10}}}

\begin{document}

    \begin{tikzpicture}[
        >={Stealth[width=8pt, length=10pt]},
        every node/.style={scale=2},
        x={(0.12 cm,0.11 cm)},
        y={(0 cm,1 cm)},
        z={(1 cm,0 cm)} 
        ]
        
        \draw [->] (-2,0,0) -- (48,0,0) node [at end, above] {$\lambda$};
        \draw [->] (0,-.5,0) -- (0,6,0) node [at end, left] {$y$};
        \draw [->] (0,0,-.5) -- (0,0,19) node [at end, above] {$x$};
        
        \def\t{18} \def\op{0.6}
        \def\waveback{440} \def\wavefront{650} % obvious, isn't it?
        \def\l{2.5} %length of the squares
        \def\a{1} \def\b{7} \def\c{13} % x pos of the square stacks
        
        \foreach \i in {0,9,...,\t}
            {
            \defclr
            \fill[myshadow,clr,opacity=\op] (\t-\i+3,0,\a) rectangle ++ (0,\l,\l);
            }       
        
        \foreach \i in {0,3,...,\t}
            {
            \defclr
            \fill[myshadow,clr,opacity=\op] (\t-\i+3,0,\b) rectangle ++ (0,\l,\l);
            }
        
        \foreach \i in {0,0.5,...,\t}
            {
            \defclr
            \fill[myshadow,shadow opacity=5,clr,opacity=\op] (\t-\i+3,0,\c) rectangle ++ (0,\l,\l);
            }   
            
        \def\dist{12pt}
        \node[below=\dist] at (3,0,\a+.5*\l) {RGB};
        \node[below=\dist] at (3,0,\b+.5*\l) {MSI};
        \node[below=\dist] at (3,0,\c+.5*\l) {HSI};

    \end{tikzpicture}

\end{document}

V2

答案2

暂时我得到了这样的结果:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns}

\begin{document}
 \def\total{15}
\newcommand{\plane}[3][fill=blue!10!white]{
    \pgfmathsetmacro\wavelen{650-(650-420)*#2/\total}
    \definecolor{adc}{wave}{\wavelen}
   
    \fill[opacity=0.7,adc] (#3, 0, #2) rectangle (#3+3, 3, #2);
}
\hspace*{-4cm}%
\begin{tikzpicture}[scale=.8]
% \begin{scope}[shift={(-15,0)}]
    %\coordinate (O) at (0, 0, 0);
    \draw[line width=0.4mm,->] (O,0,16) --++ (16,0,0) node[anchor=north east]{$z$};     
    \draw[line width=0.4mm,->] (O,0,16) --++ (0,8,0) node[anchor=north east]{$y$};     
    \draw[line width=0.4mm,->] (O,0,16) --++ (0,0,-25) node[anchor=east]{$\lambda$};
    
\node[below] at (2,0,17) {RGB};
\node[below] at (7,0,17) {Multispectral};
\node[below] at (12,0,17) {Hyperspectral};

    %\plane[draw=none,pattern=dots]{0};
     \def\total{15}
                
            %\foreach \x in {1,2,...,\total}
                %\plane{\x};
                
                \foreach \x in {1,7,...,\total}
                \plane{\x}{0};
                \foreach \x in {1,3,...,\total}
                \plane{\x}{5};
                \foreach \x in {1,1.5,...,\total}
                \plane{\x}{10};
%\end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容