填充不透明度、不透明度和绘制不透明度命令根本不起作用 - tikz、tikz3dplot

填充不透明度、不透明度和绘制不透明度命令根本不起作用 - tikz、tikz3dplot

我是 tex.stackexchenge 的新手。我尝试了很多次,用红色和橙色绘制圆形阴影区域,以便将它们透明地(不透明度参数为 0.3)叠加到三重井函数最小值,但我没能成功。

\documentclass[a4paper,10pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel} 
\usepackage[pdftex]{graphicx} 
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{trees}
\usetikzlibrary{arrows}
\usepackage{pst-all}
\usepackage{pstricks-add}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{fadings}
\usetikzlibrary{patterns}
\usepackage{pgfplots}
\usetikzlibrary{babel}
\usetikzlibrary{arrows}

\title{}
\author{}
\date{\today}

\begin{document}

\maketitle

\begin{figure}[h]
\begin{center}
\begin{tikzpicture}[axis/.style={->,black,thick}, miniaxis/.style={->,black}]
%----------------------------------------------------------------------------
 \draw[axis] (6,4.154700538, 0.81649658)  -- (8,4.154700538, 0.81649658) node[anchor=west]{\large $x$};
 \draw[axis] (6,4.154700538, 0.81649658) -- (6,6.154700538, 0.81649658) node[anchor=south]{\large $y$};
  \draw[axis] (6,4.154700538, 0.81649658) -- (6,4.154700538, 2.81649658) node[anchor=north]{\large $z$};
   %-------------------------------------------------------------------------------
 \fill[top color=yellow!50!black,bottom color=yellow!10,middle color=yellow,shading=axis,opacity=0.25] (0,0) circle (2cm and 0.5cm);
\fill[left color=yellow!50!black,right color=yellow!50!black,middle color=yellow!50,shading=axis,opacity=0.25] (2,0) -- (2,0.55) arc (360:180:2cm and 0.5cm) -- (-2,0) arc (180:360:2cm and 0.5cm);
 \fill[top color=yellow!90!,bottom color=yellow!2,middle color=yellow!30,shading=axis,opacity=0.25] (0,0.55) circle (2cm and 0.5cm);
  \draw (-2,0.55) -- (-2,0) arc (180:360:2cm and 0.5cm) -- (2,0.55) ++ (-2,0) circle (2cm and 0.5cm);

  %-------------------------------------------------------------------------
   \fill[top color=yellow!50!black,bottom color=yellow!10,middle color=yellow,shading=axis,opacity=0.25] (0,8) circle (2cm and 0.5cm);
   \fill[left color=yellow!50!black,right color=yellow!50!black,middle color=yellow!50,shading=axis,opacity=0.25] (2,8) -- (2,8.55) arc (360:180:2cm and 0.5cm) -- (-2,8) arc (180:360:2cm and 0.5cm);
  \fill[top color=yellow!90!,bottom color=yellow!2,middle color=yellow!30,shading=axis,opacity=0.25] (0,8.55) circle (2cm and 0.5cm);
  \draw (-2,8.55) -- (-2,8) arc (180:360:2cm and 0.5cm) -- (2,8.55) ++ (-2,0) circle (2cm and 0.5cm);
   %------------------------------------------------------------------------
  \pgfmathsetmacro{\e}{2.8}   % eccentricity
  \pgfmathsetmacro{\a}{1.395}
  \pgfmathsetmacro{\b}{(\a*sqrt((\e)^2-1)} 
  \draw plot[ domain=-0.9:0.9] ({\a*cosh(\x)},{\b*sinh(\x)+4.275});
  \draw plot[ domain=-0.9:0.9] ({-\a*cosh(\x)},{\b*sinh(\x)+4.275});
  %------------------------------------------------------------------------- 
  \pgfmathsetmacro{\c}{3.395}
 \pgfmathsetmacro{\d}{0.405}
  \pgfmathsetmacro{\f}{2.50}
  \draw[ultra thick, color=PineGreen]  node [left=6cm, above=6cm, color=black] {{\fontfamily{phv}\selectfont Potenziale a Tripla Buca}} plot[domain=-4:4, samples=100] ({\x}, {\c*(-exp(-2*\d*(\x+\f)^2)-exp(-2*\d*(\x-\f)^2)-exp(-2*\d*(\x+0)^2))+8.0});
   %------------------------------------------------------------------------
  \pgfmathsetmacro{\g}{1.75}
   \pgfmathsetmacro{\h}{0.18}
  \draw[thick, color=black] plot[domain=-4:4] ({\x}, {4});
 \draw[ultra thick, color=Magenta] node [left=6cm, above=2cm, color=black] {{\fontfamily{phv}\selectfont Funzione di Modo}} plot[domain=-4:4, samples=100] ({\x}, {\g*\x*(-exp(-2*\h*(\x)^2))+2.5});
     %----------------------------------------------------------------------
    \shade[inner color=red, outer color=orange, fill opacity=0.3] (0,5) circle (0.5);
    \shade[inner color=red, outer color=orange, fill opacity=0.3] (-2.5,5) circle (0.5);
    \shade[inner color=red, outer color=orange, fill opacity=0.3] (2.5,5) circle (0.5);
   %------------------------------------------------------------------------
  \draw[double, style=-triangle 90, line width=2pt, blue] (0,-2) -- (0,-1);
\draw (0,-2.5) node {{\fontfamily{phv}\selectfont Laser di Pompa}};
 \end{tikzpicture}
 \end{center}
  \end{figure}

   \end{document}

上面列出的代码的输出。

答案1

您正在使用哪个引擎?

\usepackage[pdftex]{graphicx} 

这表示您正在使用 pdfTeX。但是,如果是这样,最好让它graphicx自己弄清楚。自动检测在大多数情况下都有效,并且更可取,因为它更强大、更灵活。

然而,

\usepackage{pst-all}
\usepackage{pstricks-add}

这些行表明您不能使用 pdfTeX,因为它不支持pstricks

实际上,你发出的是混杂的信息。结果是,同样的 TiZ 代码将产生不同的效果。特别是我敢打赌你的控制台输出(和日志)包含大量关于非 PDF 特殊字符被忽略的警告。这就是你的透明度。

Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!

这是在要求配置可理解 postscript 的工作流程后使用 pdfTeX 进行编译的结果pstricks。pdfTeX 不执行 postscript,因此它会忽略这些内容。

如何处理这个问题取决于你的需求。不过请注意,你的例子远非最简化的。

这是非最小图片的一个版本,带有一个更简约的前言,可以演示这个问题。

\documentclass[border=10pt,multi,tikz,dvipsnames]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pst-all}
\usepackage{pstricks-add}
\usepackage{pgfplots}
\usetikzlibrary{arrows}

\begin{document}
\begin{tikzpicture}[axis/.style={->,black,thick}, miniaxis/.style={->,black}]
  \draw[axis] (6,4.154700538, 0.81649658)  -- (8,4.154700538, 0.81649658) node[anchor=west]{\large $x$};
  \draw[axis] (6,4.154700538, 0.81649658) -- (6,6.154700538, 0.81649658) node[anchor=south]{\large $y$};
  \draw[axis] (6,4.154700538, 0.81649658) -- (6,4.154700538, 2.81649658) node[anchor=north]{\large $z$};
  \fill[top color=yellow!50!black,bottom color=yellow!10,middle color=yellow,shading=axis,opacity=0.25] (0,0) circle (2cm and 0.5cm);
  \fill[left color=yellow!50!black,right color=yellow!50!black,middle color=yellow!50,shading=axis,opacity=0.25] (2,0) -- (2,0.55) arc (360:180:2cm and 0.5cm) -- (-2,0) arc (180:360:2cm and 0.5cm);
  \fill[top color=yellow!90!,bottom color=yellow!2,middle color=yellow!30,shading=axis,opacity=0.25] (0,0.55) circle (2cm and 0.5cm);
  \draw (-2,0.55) -- (-2,0) arc (180:360:2cm and 0.5cm) -- (2,0.55) ++ (-2,0) circle (2cm and 0.5cm);
  \fill[top color=yellow!50!black,bottom color=yellow!10,middle color=yellow,shading=axis,opacity=0.25] (0,8) circle (2cm and 0.5cm);
  \fill[left color=yellow!50!black,right color=yellow!50!black,middle color=yellow!50,shading=axis,opacity=0.25] (2,8) -- (2,8.55) arc (360:180:2cm and 0.5cm) -- (-2,8) arc (180:360:2cm and 0.5cm);
  \fill[top color=yellow!90!,bottom color=yellow!2,middle color=yellow!30,shading=axis,opacity=0.25] (0,8.55) circle (2cm and 0.5cm);
  \draw (-2,8.55) -- (-2,8) arc (180:360:2cm and 0.5cm) -- (2,8.55) ++ (-2,0) circle (2cm and 0.5cm);
  \pgfmathsetmacro{\e}{2.8}   % eccentricity
  \pgfmathsetmacro{\a}{1.395}
  \pgfmathsetmacro{\b}{(\a*sqrt((\e)^2-1)}
  \draw plot[ domain=-0.9:0.9] ({\a*cosh(\x)},{\b*sinh(\x)+4.275});
  \draw plot[ domain=-0.9:0.9] ({-\a*cosh(\x)},{\b*sinh(\x)+4.275});
  \pgfmathsetmacro{\c}{3.395}
  \pgfmathsetmacro{\d}{0.405}
  \pgfmathsetmacro{\f}{2.50}
  \draw[ultra thick, color=PineGreen]  node [left=6cm, above=6cm, color=black] {{\fontfamily{phv}\selectfont Potenziale a Tripla Buca}} plot[domain=-4:4, samples=100] ({\x}, {\c*(-exp(-2*\d*(\x+\f)^2)-exp(-2*\d*(\x-\f)^2)-exp(-2*\d*(\x+0)^2))+8.0});
  \pgfmathsetmacro{\g}{1.75}
  \pgfmathsetmacro{\h}{0.18}
  \draw[thick, color=black] plot[domain=-4:4] ({\x}, {4});
  \draw[ultra thick, color=Magenta] node [left=6cm, above=2cm, color=black] {{\fontfamily{phv}\selectfont Funzione di Modo}} plot[domain=-4:4, samples=100] ({\x}, {\g*\x*(-exp(-2*\h*(\x)^2))+2.5});
  \shade[inner color=red, outer color=orange, fill opacity=0.3] (0,5) circle (0.5);
  \shade[inner color=red, outer color=orange, fill opacity=0.3] (-2.5,5) circle (0.5);
  \shade[inner color=red, outer color=orange, fill opacity=0.3] (2.5,5) circle (0.5);
  \draw[double, style=-triangle 90, line width=2pt, blue] (0,-2) -- (0,-1);
  \draw (0,-2.5) node {{\fontfamily{phv}\selectfont Laser di Pompa}};
\end{tikzpicture}

\end{document}

使用 pdfTeX 编译此代码会产生上述问题以及无法正常工作的输出。

pdfTeX 与 postscript 混淆

现在,让我们注释掉pstricks序言中的几行。

% \usepackage{pst-all}
% \usepackage{pstricks-add}

再次使用 pdfTeX 进行编译,一切都按预期工作。

pdfTeX

或者,我们可以切换到可以处理后记的编译器。例如,我们可以按如下方式修改前言。

% \usepackage[T1]{fontenc}
% \usepackage[utf8]{inputenc}
\usepackage{pst-all}
\usepackage{pstricks-add}

如果我们使用 XeTeX 而不是 pdfTeX 进行编译,我们就能得到预期的输出。

特克斯

或者,您可以使用传统的 TeX(无需更改前导码)来编译 DVI 并处理 DVI 以生成最终的 PDF。TeX 对 postscript 的了解并不比 pdfTeX 更好,但在这种情况下,postscript 特例可以传递给后处理器进行解释。(dvipdfmxdvips或其他。)

答案2

比较:

\documentclass[border=10pt,multi,tikz]{standalone}    
\begin{document}
\begin{tikzpicture}
  \fill [gray] (-.5,-.5) rectangle (4.5,1.5);
  \shade[inner color=red, outer color=orange, fill opacity=0.3] (0,0) rectangle (1,1);
  \shade[inner color=red, outer color=orange, fill opacity=1] (1.5,0) rectangle (2.5,1);
  \shade[inner color=red!30, outer color=orange!30] (3,0) rectangle (4,1);
\end{tikzpicture}
\end{document}

比较

答案3

在我看来,阴影和不透明度(以及填充和绘制不透明度)不能结合在一起。

因此,

\shade[inner color=red, outer color=orange, fill opacity=0.3] 

会产生与

\shade[inner color=red, outer color=orange, fill opacity=1]

一种解决方法是手动将阴影颜色设置为更透明。例如,

\shade[inner color=red!30, outer color=orange!30, fill opacity=0.3]

需要注意的是:不透明度将对阴影区域内的文本起作用,这就是我将其留在那里的原因。

相关内容