我如何获得这种填充模式?

我如何获得这种填充模式?

我们如何在 tikz 矩形上获得这种 3D 效果?在此处输入图片描述

答案1

欢迎来到 TeX.SE!在这里我重点讨论如何获取塑料矩形的问题。我使用的方法有一个缺点,就是需要\addplot为每个条形使用单独的路径图。这是因为我使用的是path pictures,出于某种原因,整个图只有一个路径图,而不是每个条形图。当然可以通过循环绘制条形图来简化事情。

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\tikzset{plastic bar/.style={preaction={
path picture={
\fill[blue!40] 
 ([xshift=3pt]path picture bounding box.south west)  
 rectangle
 ([xshift=-3pt,yshift=-3pt]path picture bounding box.north east);
\fill[blue!80] 
 ([xshift=-3pt,yshift=-3pt]path picture bounding box.north east)
 -- (path picture bounding box.north east) --
 (path picture bounding box.south east) --  
 ([xshift=-3pt]path picture bounding box.south east);  
\fill[blue!20] 
 ([xshift=-3pt,yshift=-3pt]path picture bounding box.north east)
 -- (path picture bounding box.north east) --
 (path picture bounding box.north west) --  
 ([xshift=3pt,yshift=-3pt]path picture bounding box.north west);  
\fill[blue!60] 
 ([xshift=3pt,yshift=-3pt]path picture bounding box.north west)
 -- (path picture bounding box.north west) --
 (path picture bounding box.south west) --  
 ([xshift=3pt]path picture bounding box.south west);  
}}
}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar,bar width=9,xmin=10,xmax=65,ymax=110,ymin=-5,bar shift=-10,
axis lines=middle,yticklabel={$\pgfmathprintnumber{\tick}\%$}]
\addplot[draw=none,plastic bar]  coordinates {(35,10)};
\addplot[draw=none,plastic bar]  coordinates {(45,30)};
\addplot[draw=none,plastic bar]  coordinates {(55,80)};
\addplot[draw=none,plastic bar]  coordinates {(65,100)};
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容