2

i´m trying to make this plot:

enter image description here

As you can see, I am having trouble on the right side. I want to make the colored regions disappear softly to the right. To make that I defined, for each color, two regions. On the big (left) one I just use the "fill between" classically, and then I added continuously on its right, a small region where I use again "fill between" but with the options "left color" and "right color".

But it happens to appear those gray vertical lines bordering the secondly defined regions where the color transition is made... I cannot understand what I am doing wrong.

Any idea?

Thanks in advance!

\documentclass{standalone}
\usepackage[american,cuteinductors,smartlabels]{circuitikz}
\tikzstyle{every path}=[line width=0.8pt,line cap=round,line join=round]
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\newcommand*{\rom}[1]{\expandafter\@slowromancap\romannumeral #1@}

\begin{document}
\begin{tikzpicture}

\newcommand{\degPunit}{20}

% AXIS
\draw[thin, ->] (-.2,0) -- (12,0) node[right] {$D$};
\draw[thin, ->] (0,-.2) -- (0,10) node[above] {$\alpha$ (deg)};

% TICKS
\draw[very thin] (1,0) -- ++(0,-.1) node[below] {$1$};
\draw[very thin] (2,0) -- ++(0,-.1) node[below] {$2$};
\draw[very thin] (3,0) -- ++(0,-.1) node[below] {$3$};
\draw[very thin] (4,0) -- ++(0,-.1) node[below] {$4$};
\draw[very thin] (5,0) -- ++(0,-.1) node[below] {$5$};
\draw[very thin] (6,0) -- ++(0,-.1) node[below] {$6$};
\draw[very thin] (7,0) -- ++(0,-.1) node[below] {$7$};
\draw[very thin] (8,0) -- ++(0,-.1) node[below] {$8$};
\draw[very thin] (9,0) -- ++(0,-.1) node[below] {$9$};
\draw[very thin] (10,0) -- ++(0,-.1) node[below] {$10$};
\draw[very thin] (11,0) -- ++(0,-.1) node[below] {$11$};

\draw[very thin] (0,180/20) -- ++(-.1,0) node[left] {$180$};
\draw[very thin] (0,150/20) -- ++(-.1,0) node[left] {$150$};
\draw[very thin] (0,120/20) -- ++(-.1,0) node[left] {$120$};
\draw[very thin] (0,90/20) -- ++(-.1,0) node[left] {$90$};
\draw[very thin] (0,60/20) -- ++(-.1,0) node[left] {$60$};
\draw[very thin] (0,30/20) -- ++(-.1,0) node[left] {$30$};
    
\node[below] at (.1,-.1) {\mbox{$0$}};
\node[left] at (-.1,0) {\mbox{$0$}};
                        

% AUX LINES 
\draw[dotted,color=gray] (0,9) -- (12,9);
\draw[dotted,color=gray] (1,0) -- (1,10);
    
% GRAPHS
\draw[name path=A1, color=black, samples = 200, domain=(1:11)] plot (\x,{acos(2/\x -1)/\degPunit});    
\draw[name path=A2, dashed ,color=black, samples = 200, domain=(11:11.5)] plot (\x,{acos(2/\x -1)/\degPunit});    

\node[right] at (11.5,7.3) {$\alpha^* (D)$};

\draw[name path=B1, color=gray, dashed, samples = 200, domain=(1:11.5)] plot (\x,{acos(1/\x)/\degPunit}); 
\node[right] at (11.5,4.3) {$\alpha (P = 0)$};
\node[right] at (7,5.5) {$\alpha (P > 0)$};
\node[right] at (7,2.2) {$\alpha (P < 0)$};


% COLORED REGIONS

\path[name path=X1, samples = 200, domain=(1:11)] plot (\x,0);  
\path[name path=X2, samples = 20, domain=(11:11.5)] plot (\x,0);    

\path[name path=C, samples = 200, domain=(11:11.5)] plot (\x,0);    


\begin{axis}[
axis lines = none,
xmin=0, xmax=12,
ymin=0, ymax=10,
width = 13.55cm,
height = 11.58cm]
\addplot[fill=green!20,draw = none] fill between[of=A1 and X1];
\addplot [name path=Y, draw = none]    
table[row sep=crcr]{%
0   0\\
0   9\\
};
\addplot [name path=D1, draw = none]
  table[row sep=crcr]{%
1   0\\
1   9\\
};
\addplot[fill=red!40,draw = none] fill between[of=Y and D1];

\addplot [name path=X180, draw = none]
  table[row sep=crcr]{%
1   9\\
11  9\\
};
\addplot [name path=X1802, draw = none]
  table[row sep=crcr]{%
11  9\\
11.5    9\\
};
\addplot[fill=red!20,draw = none] fill between[of=X180 and A1];

\addplot[draw = none, left color=red!20, right color=white] fill between[of=X1802 and A2];

\addplot[draw = none, left color=green!20, right color=green!0 ] fill between[of=A2 and X2];

\end{axis}

\node[right] at (.3,8) {\rom{1}};
\node[right] at (10,8) {\rom{2}};
\node[right] at (10,6) {\rom{3}};



% MARKS

\draw[dotted,color=gray] (2.4,0) -- (2.4,6);
\draw[dotted,color=gray] (0,3) -- (2.4,3);
\draw[dotted,color=gray] (0,6) -- (2.4,6);
\draw[dotted,color=gray] (0,4.98) -- (2.4,4.98);
\draw[dotted,color=gray] (0,1.5) -- (2.4,1.5);

\draw[dotted,color=gray] (0,3) -- (3.36,3);
\draw[dotted,color=gray] (1.32,0) -- (1.32,3);
\draw[dotted,color=gray] (1.92,0) -- (1.92,3);
\draw[dotted,color=gray] (2.4,0) -- (2.4,3);
\draw[dotted,color=gray] (2.88,0) -- (2.88,3);
\draw[dotted,color=gray] (3.36,0) -- (3.36,3);


\filldraw[black] (2.4,3) circle (2pt) node[anchor=north west]{};
\filldraw[black] (2.4,6) circle (2pt) node[anchor=west]{};
\filldraw[black] (2.4,4.98) circle (2pt) node[anchor=west]{};
\filldraw[black] (2.4,1.5) circle (2pt) node[anchor=west]{};
\filldraw[black] (2.4,0) circle (2pt) node[anchor=west]{};
    
\filldraw[black] (1.32,3) circle (2pt) node[anchor=west]{};
\filldraw[black] (1.92,3) circle (2pt) node[anchor=west]{};
\filldraw[black] (2.88,3) circle (2pt) node[anchor=west]{};
\filldraw[black] (3.36,3) circle (2pt) node[anchor=west]{};



\end{tikzpicture}
\end{document}
2
  • I have the feeling that this is just a rendering error. If you zoom into this area, the effect will probably disappear. Jul 29 at 12:46
  • Unrelated but your code seems to come from another source and contains many redundancies and useless lines (like node[anchor=west]{} which produces nothing).
    – SebGlav
    Jul 30 at 9:47

1 Answer 1

1

Welcome to TeX.SX! This is probably just a rendering error. You can try to use the fadings library and use fill=red!20, path fading=east and fill=green!20, path fading=east for the fadings:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{fadings}

\tikzset{
    every path/.style={
        line width=0.8pt,
        line cap=round,
        line join=round
    }
}

\newcommand*{\rom}[1]{\expandafter\@slowromancap\romannumeral #1@}

\begin{document}
\begin{tikzpicture}

\newcommand{\degPunit}{20}

% AXIS
\draw[thin, ->] (-.2,0) -- (12,0) node[right] {$D$};
\draw[thin, ->] (0,-.2) -- (0,10) node[above] {$\alpha$ (deg)};

% TICKS
\draw[very thin] (1,0) -- ++(0,-.1) node[below] {$1$};
\draw[very thin] (2,0) -- ++(0,-.1) node[below] {$2$};
\draw[very thin] (3,0) -- ++(0,-.1) node[below] {$3$};
\draw[very thin] (4,0) -- ++(0,-.1) node[below] {$4$};
\draw[very thin] (5,0) -- ++(0,-.1) node[below] {$5$};
\draw[very thin] (6,0) -- ++(0,-.1) node[below] {$6$};
\draw[very thin] (7,0) -- ++(0,-.1) node[below] {$7$};
\draw[very thin] (8,0) -- ++(0,-.1) node[below] {$8$};
\draw[very thin] (9,0) -- ++(0,-.1) node[below] {$9$};
\draw[very thin] (10,0) -- ++(0,-.1) node[below] {$10$};
\draw[very thin] (11,0) -- ++(0,-.1) node[below] {$11$};

\draw[very thin] (0,180/20) -- ++(-.1,0) node[left] {$180$};
\draw[very thin] (0,150/20) -- ++(-.1,0) node[left] {$150$};
\draw[very thin] (0,120/20) -- ++(-.1,0) node[left] {$120$};
\draw[very thin] (0,90/20) -- ++(-.1,0) node[left] {$90$};
\draw[very thin] (0,60/20) -- ++(-.1,0) node[left] {$60$};
\draw[very thin] (0,30/20) -- ++(-.1,0) node[left] {$30$};
    
\node[below] at (.1,-.1) {\mbox{$0$}};
\node[left] at (-.1,0) {\mbox{$0$}};
                        
% AUX LINES 
\draw[dotted, color=gray] (0,9) -- (12,9);
\draw[dotted, color=gray] (1,0) -- (1,10);
    
% GRAPHS
\draw[name path=A1, color=black, samples=200, domain=(1:11)] plot (\x,{acos(2/\x -1)/\degPunit});    
\draw[name path=A2, dashed, color=black, samples=200, domain=(11:11.5)] plot (\x,{acos(2/\x -1)/\degPunit});    

\node[right] at (11.5,7.3) {$\alpha^* (D)$};

\draw[name path=B1, color=gray, dashed, samples=200, domain=(1:11.5)] plot (\x,{acos(1/\x)/\degPunit}); 
\node[right] at (11.5,4.3) {$\alpha (P = 0)$};
\node[right] at (7,5.5) {$\alpha (P > 0)$};
\node[right] at (7,2.2) {$\alpha (P < 0)$};

% COLORED REGIONS

\path[name path=X1, domain=(1:11)] plot (\x,0);  
\path[name path=X2, domain=(11:11.5)] plot (\x,0);    

% \path[name path=C, domain=(11:11.5)] plot (\x,0);    

\begin{axis}[
    axis lines=none,
    xmin=0, xmax=12,
    ymin=0, ymax=10,
    width=13.55cm,
    height=11.58cm]
\addplot[fill=green!20] fill between[of=A1 and X1];
\addplot [name path=Y, draw=none]    
    table[row sep=crcr]{%
        0   0\\
        0   9\\
    };
\addplot [name path=D1, draw=none]
    table[row sep=crcr]{%
        1   0\\
        1   9\\
    };
\addplot[fill=red!40] fill between[of=Y and D1];

\addplot [name path=X180, draw=none]
    table[row sep=crcr]{%
        1   9\\
        11  9\\
    };
\addplot [name path=X1802, draw=none]
    table[row sep=crcr]{%
        11  9\\
        11.5    9\\
    };
\addplot[fill=red!20] fill between[of=X180 and A1];

\addplot[fill=red!20, path fading=east] fill between[of=X1802 and A2];   % <--- !

\addplot[fill=green!20, path fading=east] fill between[of=A2 and X2];    % <--- !

\end{axis}

\node[right] at (.3,8) {\rom{1}};
\node[right] at (10,8) {\rom{2}};
\node[right] at (10,6) {\rom{3}};

% MARKS

\draw[dotted, color=gray] (2.4,0) -- (2.4,6);
\draw[dotted, color=gray] (0,3) -- (2.4,3);
\draw[dotted, color=gray] (0,6) -- (2.4,6);
\draw[dotted, color=gray] (0,4.98) -- (2.4,4.98);
\draw[dotted, color=gray] (0,1.5) -- (2.4,1.5);

\draw[dotted, color=gray] (0,3) -- (3.36,3);
\draw[dotted, color=gray] (1.32,0) -- (1.32,3);
\draw[dotted, color=gray] (1.92,0) -- (1.92,3);
\draw[dotted, color=gray] (2.4,0) -- (2.4,3);
\draw[dotted, color=gray] (2.88,0) -- (2.88,3);
\draw[dotted, color=gray] (3.36,0) -- (3.36,3);

\filldraw[black] (2.4,3) circle (2pt) node[anchor=north west]{};
\filldraw[black] (2.4,6) circle (2pt) node[anchor=west]{};
\filldraw[black] (2.4,4.98) circle (2pt) node[anchor=west]{};
\filldraw[black] (2.4,1.5) circle (2pt) node[anchor=west]{};
\filldraw[black] (2.4,0) circle (2pt) node[anchor=west]{};
    
\filldraw[black] (1.32,3) circle (2pt) node[anchor=west]{};
\filldraw[black] (1.92,3) circle (2pt) node[anchor=west]{};
\filldraw[black] (2.88,3) circle (2pt) node[anchor=west]{};
\filldraw[black] (3.36,3) circle (2pt) node[anchor=west]{};

\end{tikzpicture}
\end{document}

enter image description here

2
  • Perfect! Thank you very much! The color transition is still not 100 % smooth (now we have a white line), but is definitely way better, and I think I can live with it. But if you have also a suggestion for correcting that, it would be nice to hear it!
    – DerSpanier
    Jul 29 at 13:08
  • The white line is probably also a rendering issue. In my viewer I cannot see it. Jul 29 at 13:19

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.