5

I'm new to tex.stackexchenge. I tried for many and many times to draw the circular shaded areas in red and orange in such a way to superimpose them in transparency (with an opacity parameter of 0.3) to the Triple Well function minima, but I didn't manage to to it.

\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}

The output of the code listed above.

1

Which engine are you using?

\usepackage[pdftex]{graphicx} 

This says you are using pdfTeX. However, if you are, it is best to let graphicx figure that out for itself. Auto-detection works in most cases and is preferable as it is more robust and flexible.

However,

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

these lines say that you cannot be using pdfTeX because it does not support pstricks.

In effect, you are sending mixed messages. The result is that the same TikZ code will have different effects. In particular I bet that your console output (and log) contains lots of warnings about non-PDF specials being ignored. This is your transparency.

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!

This is the result of compiling with pdfTeX after asking pstricks to configure things for a workflow which understands postscript. pdfTeX doesn't do postscript, so it ignores this stuff.

How you deal with this depends on what you need. Do note, however, that your example is very far from minimal.

Here's a version of the non-minimal picture with a more-minimal preamble which demonstrates the problem.

\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}

Compiling this code with pdfTeX produces the complaints mentioned above along with the non-working output.

pdfTeX with postscript confusion

Now, let's comment out the pstricks lines in the preamble.

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

Compiling with pdfTeX again, everything works as expected.

pdfTeX

Alternatively, we can switch to a compiler which can handle postscript. For example, we can alter the preamble as follows.

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

If we compile with XeTeX, rather than pdfTeX, we get the expected output just fine.

XeTeX

Or you could use traditional TeX, without changing the preamble, to compile DVI and process the DVI to produce the final PDF. TeX doesn't know postscript any better than pdfTeX, but the postscript specials can be passed through for interpretation by the post-processor in this case. (dvipdfmx or dvips or whatever.)

1

Compare:

\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}

comparison

0

it seems to me that shades and opacity (also fill and draw opacity) do not go together.

Hence,

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

will produce the same as

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

A workaround is to set the color of your shadings more transparent manually. e.g.,

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

As a remark: opacity will work on text inside the shaded region, that is why I left it in there.

  • You didn't test this at all, did you? I'm afraid that your diagnosis is just wrong. Shadings can be transparent. There can be complications re. fill vs. shade, but they aren't pertinent here. And inner color=red!30 does not make it 30% transparent. It mixes 30% red with 70% white. So if you were right, your suggested workaround would not help unless the OP doesn't really want transparency at all. But it is obvious from the example that transparency is wanted here and not just a paler shade of the colour at 100% opacity. – cfr Sep 13 '16 at 3:00
  • See tex.stackexchange.com/a/329296 below. (I will delete this later, if you let me know, as it is not relevant to answering the question. But it is too much for a comment.) – cfr Sep 13 '16 at 3:08
  • I did test this and it did work. I found this problem since I had the same difficulties. Did you test my solution? – user3710638 Sep 14 '16 at 10:50
  • Did you test it on a non-white background? You are not getting transparency, which is why it appears to work. The example I linked to tests your solution on a non-white background so, yes, obviously I did test because I wrote the example. If the OP doesn't really need transparency, it is different. But I don't think that's the case here. – cfr Sep 14 '16 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.