0

i want to fill this area in blue, could anyone help me pls? (i am a beginner)

thanks a lot

\usepackage{tikz}
\usetikzlibrary{decorations,arrows, intersections, through}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\usetikzlibrary{quotes,angles}
\begin{tikzpicture}
\begin{axis} [xtick distance=1,legend pos=outer north east,xmin=-3,xmax=3,ymin=-8,ymax=8] 
  \addplot +[no markers,
  raw gnuplot,
  very thick,
  empty line = jump % not strictly necessary, as this is the default behaviour in the development version of PGFPlots
  , dotted, name path = A] gnuplot {
  set contour base;
  set cntrparam levels discrete 0.003;
  unset surface;
  set view map;
  set isosamples 500;
  set samples 500;
  splot x + 0.25*y^2 - 1;
};
\addlegendentry{$\mathfrak{Re}(z^2)= 1 - \frac{1}{4} (\mathfrak{Im}(z^2))^2$}
\addplot +[no markers,
  raw gnuplot,
  very thick,
  empty line = jump % not strictly necessary, as this is the default behaviour in the development version of PGFPlots
  , dotted] gnuplot {
  set contour base;
  set cntrparam levels discrete 0.003;
  unset surface;
  set view map;
  set isosamples 500;
  set samples 500;
  splot x - 1;
};
\addlegendentry{$\mathfrak{Re}(z)= 1$}
\end{axis}
\end{tikzpicture}

fill in blue

5
  • Welcome to TeX.SE! Preferably, could you extend your code into something we can compile please?
    – JamesT
    Jun 13, 2023 at 11:16
  • Do you really need to plot this using gnuplot? Jun 13, 2023 at 12:34
  • sorry, i have added the package, of course gnuplot is not necessary. thanks in advance
    – Smile
    Jun 13, 2023 at 12:39
  • At least the vertical line could be plotted with just \addplot+[no markers, very thick, dotted] coordinates { (1,\pgfkeysvalueof{/pgfplots/ymin} (1,\pgfkeysvalueof{/pgfplots/ymax}) }; which would probably enhance compilation time. Jun 13, 2023 at 12:51
  • thanks very helpful
    – Smile
    Jun 13, 2023 at 13:17

1 Answer 1

1

If you want to use a path to draw an area, you need to make sure that it is continuous. Therefore, you need to make sure that the function you use to plot this path is also calculated in a continuous way. This is not the case in your current set up as can be seen if we fill it:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}
\begin{axis} [
    xtick distance = 1, 
    legend pos = outer north east,
    xmin = -3, xmax = 3, ymin = -8, ymax = 8
  ] 
  \addplot +[no markers,
    raw gnuplot,
    very thick, 
    dotted, 
    fill = cyan!50
  ] gnuplot {
    set contour base;
    set cntrparam levels discrete 0.003;
    unset surface;
    set view map;
    set isosamples 500;
    set samples 500;
    splot x + 0.25*y^2 - 1;
  };
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Obviously, the function is plotted stepwise and the sections with positive and negative y values are probably plotted in an alternating way which in any case results in a nice result when drawn but, sadly, nothing we can use to create a fillable area. You would need to play around with the settings of gnuplot to come up with something usable.

However, I would suggest that you don't use gnuplots to plot the functions at all as they are both relatively simple. Also, you should probably split the function for the curve so that you get an upper and a lower branch:

\documentclass[border=10pt]{standalone}
\usepackage{amssymb}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{backgrounds}

\begin{document}
\begin{tikzpicture}
\begin{axis} [
    xtick distance = 1, 
    legend pos = outer north east,
    xmin = -3, xmax = 3, ymin = -8, ymax = 8
  ] 
  \addplot+[
    no markers,
    very thick,
    dotted, 
    smooth,
    samples = 101,
    name path = A upper
  ] { sqrt( 4 - 4*x ) };
  \addlegendentry{$\mathfrak{Re}(z^2) = 1 - \frac{1}{4} (\mathfrak{Im}(z^2))^2$}
  \addplot+[
    no markers,
    very thick,
    dotted, 
    blue,
    forget plot,
    smooth,
    samples = 101,
    name path = A lower
  ] { -1 * sqrt( 4 - 4*x ) };
  \addplot+[
    no markers,
    very thick,
    dotted
  ] coordinates {
    (1,\pgfkeysvalueof{/pgfplots/ymin}) (1,\pgfkeysvalueof{/pgfplots/ymax})
  };
  \addlegendentry{$\mathfrak{Re}(z) = 1$}

  \begin{scope}[on background layer]
    \path[name path = plot box upper]  
      (\pgfkeysvalueof{/pgfplots/xmin},0) rectangle
      (\pgfkeysvalueof{/pgfplots/xmax},\pgfkeysvalueof{/pgfplots/ymax});
    \path[name path = plot box lower]  
      (\pgfkeysvalueof{/pgfplots/xmin},0) rectangle
      (\pgfkeysvalueof{/pgfplots/xmax},\pgfkeysvalueof{/pgfplots/ymin});
    
    \fill[cyan!50, intersection segments = {
      of = {A upper and plot box upper},
      sequence = {L*[reverse] -- R2}
    }] -- cycle; 
    \fill[cyan!50, intersection segments = {
      of = {A lower and plot box lower},
      sequence = {L*[reverse] -- R2}
    }] -- cycle; 
  \end{scope}
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

1
  • I am so grateful Best regard
    – Smile
    Jun 13, 2023 at 15:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .