0

My code for tikzpicture:

\begin{tikzpicture} [domain=0:4]
\begin{axis}[     axis lines = left,     xlabel = $\lambda$,     ylabel = {$x$}, ] 
\addplot [ fill=red, opacity=.4,    domain=1:6,      samples=100,      color=red, thick, mark=none ] {sqrt((0.1*x^(8)+x^(6)+0.3*x^(2)+3)/(x^(8)))} -- (axis cs:0,40) \closedcycle; 
\addlegendentry{$D(\lambda)$} 
\addplot [  fill=blue, opacity=.4,   domain=1:6,      samples=100,      color=blue, thick, mark=none    ]     {sqrt((0.1*x^(8)+x^(6)/3+0.1*x^(2)+5/3)/(x^(8)))} -- (axis cs:0,40) \closedcycle; 
\addlegendentry{$f(\lambda)$}

\addplot [ domain=1:6, fill=yellow!25,    opacity=.4, samples=100,      color=green, thick, mark=none  ]     {sqrt((0.1*x^(8)-x^(6)-0.3*x^(2)-1)/(x^(8)))} \closedcycle; 

\addlegendentry{$g(\lambda)$}  
\end{axis} 
\end{tikzpicture}

is giving a weird diagonal at right:

enter image description here

Why is it happening? How could I obtain a straight line under the legends?

  • (1) welcome, (2) in order for us to help you please expand your sniplet to a full (but minimal) example, that we can copy and use as is in order for get the image you posted. – daleif Apr 08 '19 at 09:15
  • Besides how is this question related to LyX? – daleif Apr 08 '19 at 09:16
  • I am compiling with Lyx. I mentioned just for help. – gibarian Apr 08 '19 at 09:18
  • The effect comes from -- (axis cs:0,40), which is very high up but not above the end point of the plot. –  Apr 08 '19 at 09:18

1 Answers1

0

The effect comes from -- (axis cs:0,40), which is very high up but not vertically above the end point of the plot. This is one way to get a vertical line.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture} [domain=0:4]
\begin{axis}[axis lines = left,     xlabel = $\lambda$,     ylabel = {$x$}, ] 
\addplot[fill=red, opacity=.4,domain=1:6, samples=100,color=red, 
thick, mark=none ] {sqrt((0.1*x^(8)+x^(6)+0.3*x^(2)+3)/(x^(8)))} 
coordinate[pos=0] (aux0)  |- (aux0)
\closedcycle; 
\addlegendentry{$D(\lambda)$} 
\addplot[fill=blue, opacity=.4,domain=1:6,samples=100,color=blue, 
thick, mark=none]     {sqrt((0.1*x^(8)+x^(6)/3+0.1*x^(2)+5/3)/(x^(8)))} 
|- (aux0)\closedcycle; 
\addlegendentry{$f(\lambda)$}

\addplot[domain=3.2:6, fill=yellow!25,    
opacity=.4, samples=100,      color=green, thick, mark=none  ]     
{sqrt((0.1*x^(8)-x^(6)-0.3*x^(2)-1)/(x^(8)))} \closedcycle; 

\addlegendentry{$g(\lambda)$}  
\end{axis} 
\end{tikzpicture}
\end{document}

enter image description here

  • Hmm, took me a while to understand the coordinate[pos=0] (aux0) |- (aux0), one might easily think that (aux0) |- (aux0) is what is being evaluated. – daleif Apr 08 '19 at 09:49
  • @daleif Yes, this is TikZ syntax, and a similar question came up e.g. here. –  Apr 08 '19 at 14:42