2

As per a suggestion, I'm splitting my previous (multiple) question into separate parts.

I want part of the area below a curve to be shaded, but using a filled rectangle results (of course) in the top part of the crunch to be shaded (when it shoudn't be) and the bottom part not to be shaded (when it should).

enter image description here

My code is

\documentclass{article}
\usepackage{tikz,pgfplots}

\usepgfplotslibrary{fillbetween}

\pgfplotsset{compat = newest}

\begin{document}

\begin{figure} \begin{tikzpicture} \begin{axis}[ ticks=none, axis x line=bottom, axis y line=left, axis y discontinuity=crunch, xmin=0,xmax=1.3, ymin=0.5,ymax=1.3] \addplot[ domain = 0:sqrt(1/3), samples =200, ] {sqrt(7/6-x^2)}; \addplot[ domain = sqrt(1/3):sqrt(7/6), fill = gray, fill opacity = 0.1, samples =200, y filter/.expression={x==sqrt(7/6 )?0:y}, ] {sqrt(7/6-x^2)}\closedcycle; \addplot[ domain = 0:7, samples =200, ] {sqrt(5/6)}; \fill[gray, opacity = 0.1] (0,0) -- (0,0.9129) -- (0.5774,0.9129) -- (0.5774,0); \end{axis} \end{tikzpicture} \end{figure}

\end{document}

Stefan Pinnow
  • 29,535
Patricio
  • 339

1 Answers1

5
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ticks=none, 
axis x line=bottom,
axis y line=left,
axis y discontinuity=crunch,
xmin=0, xmax=1.3,
ymin=0.5, ymax=1.3,
y axis line style={name path=yaxis},
]
\addplot[
name path=circ,
domain=0:sqrt(7/6-1/4),
samples=200,
] {sqrt(7/6-x^2)};
\addplot[gray] fill between [of=yaxis and circ, reverse=false, soft clip={(-1,-1) rectangle (1,{sqrt(5/6)})}, on layer={axis background}];
\draw (0,{sqrt(5/6)}) -- (1.3,{sqrt(5/6)});
\draw ({sqrt(1/3)},0.5) -- ({sqrt(1/3)},{sqrt(5/6)});
\end{axis}
\end{tikzpicture}
\end{document}

Quarter of circle in graph partly filled

  • +1: What is the reverse=false for? – Dr. Manuel Kuehner Apr 24 '22 at 14:38
  • 1
    The default reverse=auto fails for some unknown reason resulting in a wrong filling path alike this question: https://tex.stackexchange.com/questions/641304/why-does-the-filled-area-between-the-curves-get-cut-into-a-x-shape/641308#641308 – hpekristiansen Apr 24 '22 at 15:13
  • Ah, thanks for the reply. Should this be reported as a potential bug? – Dr. Manuel Kuehner Apr 24 '22 at 17:11
  • 1
    @Dr.ManuelKuehner: Just looked at the manual again p. 444: "Configures whether the input paths specified by of need to be reversed in order to arrive at a suitable path concatenation."..."Manual reversal is necessary if pgfplots chose the wrong one.". So it is not guaranteed that auto works. -not a bug. – hpekristiansen Apr 24 '22 at 17:28
  • Again, thanks for the reply! – Dr. Manuel Kuehner Apr 24 '22 at 18:20