代码

代码

有没有办法用不同数量的红色填充这个玻璃管?我正在寻找温度计问题中发现的类似解决方案(温度计的填充物)。

我的最小例子是:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}
\draw (0,0) ellipse (1 and .5);
\draw (-1,0)--(-1,-5);
\draw (1,0)--(1,-5);
\draw (-1,-5) arc (180:360:1);

\foreach \y/\x in {-5/1,
                   -4/2,
                   -3/3,
                   -2/4%
                   }
    {
    \draw (-0.2,\y)--(0.2,\y) node[right](\x){\x};

    \foreach \z in {0.2,0.4,0.6,0.8}
                    {\draw ($(-0.1,\z) + (0,\y)$)--($(0.1,\z)+(0,\y)$);}
    };


\end{tikzpicture}

\end{document}

答案1

稍微修改一下妆容

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}
\shade[left color=red,right color=red!40] 
    (-1,-2)--(-1,-5) arc (180:360:1)  -- (1,-2) arc (0:180:1 and 0.3);
\draw (0,0) ellipse (1 and .3);
\draw (-1,0)--(-1,-5) arc (180:360:1) --(1,-5) -- (1,0);
\draw[red!90!black!70] (0,-2) ellipse (1 and .3);

\foreach \y/\x in {-5/1,-4/2,-3/3,-2/4}
    {
    \draw (-0.2,\y) to[bend right=10](0.2,\y) node[right,yslant=0.15](\x){\x};

    \foreach \z in {0.2,0.4,0.6,0.8}
       \draw ($(-0.1,\z) + (0,\y)$)to[bend right=5]($(0.1,\z)+(0,\y)$);
    };
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

高度可调:

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}    

\begin{document}
\newlength{\mylen}
\setlength{\mylen}{-3cm}                %% change here for changing length (height)
\begin{tikzpicture}
\draw (0,0) ellipse (1 and .5);
\draw (-1,0)--(-1,-5);
\draw (1,0)--(1,-5);
\draw (-1,-5) arc (180:360:1);

\fill[red!50] (-1,\mylen)--(-1,-5) arc (180:360:1) -- (1,\mylen) --cycle;
\path[fill=red!40!white,] (0,\mylen) ellipse (1 and .5);       

\foreach \y/\x in {-5/1,
                   -4/2,
                   -3/3,
                   -2/4%
                   }
    {
    \draw (-0.2,\y)--(0.2,\y) node[right](\x){\x};

    \foreach \z in {0.2,0.4,0.6,0.8}
                    {\draw ($(-0.1,\z) + (0,\y)$)--($(0.1,\z)+(0,\y)$);}
    };


\end{tikzpicture}

\end{document}

在此处输入图片描述

强制动画:

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\foreach \h in {-1.2,-1.4,...,-5}{
\begin{tikzpicture}
\draw (0,0) ellipse (1 and .3);
\draw (-1,0)--(-1,-5);
\draw (1,0)--(1,-5);
\draw (-1,-5) arc (180:360:1);

\fill[red!50] (-1,\h)--(-1,-5) arc (180:360:1) -- (1,\h) --cycle;
\path[fill=red!40!white,] (0,\h) ellipse (1 and .3);

\foreach \y/\x in {-5/1,
                   -4/2,
                   -3/3,
                   -2/4%
                   }
    {
    \draw (-0.2,\y)--(0.2,\y) node[right](\x){\x};

    \foreach \z in {0.2,0.4,0.6,0.8}
                    {\draw ($(-0.1,\z) + (0,\y)$)--($(0.1,\z)+(0,\y)$);}
    };


\end{tikzpicture}
}
\end{document}

在此处输入图片描述

答案3

两个独立的解决方案。

代码

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
    \begin{tikzpicture}
        \fill[color=red!80] (-1,-4) arc (180:0:1 and .2) -- (1,-5) arc (0:-180:1);
        \fill[color=red] (0,-4) ellipse (1 and .2);%Not necessary, it is there if the opacity is changed or a solution deleted ;)
        \fill[color=red!35] (-1,-2) arc (180:0:1 and .2) -- (1,-4) arc (0:-180:1 and .2);
        \fill[color=red!50] (0,-2) ellipse (1 and .2);
        \foreach \y/\x in {-5/1,-4/2,-3/3,-2/4}{%
            \draw (-0.2,\y) -- (0.2,\y) node[right](\x){\x};
            \foreach \z in {0.2,0.4,0.6,0.8}
               \draw ($(-0.1,\z) + (0,\y)$) -- ($(0.1,\z)+(0,\y)$);
        };
        \draw[thick] (1,0) -- (1,-5) arc (0:-180:1) -- (-1,0);
        \draw[thick] (0,0) ellipse (1 and .2);
    \end{tikzpicture}
\end{document}

结果

在此处输入图片描述

答案4

解决了

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}
\draw (0,0) ellipse (1 and .5);
\draw (-1,0)--(-1,-5) arc (180:360:1)--(1,0);

\foreach \y/\x in {-5/1,
                   -4/2,
                   -3/3,
                   -2/4%
                   }
    {
    \draw (-0.2,\y)--(0.2,\y) node[right](\x){\x};

    \foreach \z in {0.2,0.4,0.6,0.8}
                    {\draw ($(-0.1,\z) + (0,\y)$)--($(0.1,\z)+(0,\y)$);}
    };

\filldraw[fill opacity=0.5,fill=red](-1,-2)--(-1,-5) arc (180:360:1)--(1,-2);

\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容