#Graph colored region

1 messages · Page 1 of 1 (latest)

teal light
#

Hi again, im with this problem. Trying to color the region inside the area formed by 4 equation. But there is some places inside that the color doesnt go, as you can see in the picture. Also some little segments wheere the color goes and it shouldnt as you can see in the upper part of the region...
This is the code:
"\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xlabel=$x$,
ylabel=$y$,
samples=100,
domain=-1.5:3,
ymin=-0.5, ymax=2.5,
xmin=-2, xmax=3.5,
axis equal
]

% Preenchimento da região sombreada
\addplot [
  domain=-1.5:3,
  fill=gray,
  opacity=0.3
]
({x}, {sqrt(1/2 - x/3)}) -- % Arco inferior da parábola
(1.5,2) -- % Ponto final da semicircunferência
({1.5 + sqrt(1 - (0)^2)}, {1+0}) -- % Arco da semicircunferência
(-1.5,2) -- % Segmento de reta superior
cycle; % Fecha o ciclo

% Arco da parábola (1)
\addplot [
  domain=-1.5:3,
  thick,
  purple
]
{sqrt(1/2 - x/3)};

% Arco da parábola (2)
\addplot [
  domain=-1.5:1.515,
  thick,
  purple
]
{2/9*x^2 + 3/2};


 % Semi-circunferência rotacionada 90 graus para a direita
 \addplot [
     domain=-1:1, % Ajuste o domínio conforme necessário
     thick,
     purple
     ]
     ({1.5 + sqrt(1 - (x)^2)}, {x+1});

% Segmento de reta (4)
\draw[thick, purple] (-1.5,1) -- (-1.5,2);



\node at (axis cs: -1.5,1.75) [purple, anchor=east] {(4)};
\node at (axis cs: 0.25,1.95) [purple, anchor=north] {(2)};
\node at (axis cs: 0.55,0.55) [purple, anchor=north] {(1)};
\node at (axis cs: 2.5,1.5) [purple, anchor=west] {(3)};

\end{axis}
\end{tikzpicture}"
The first picture is how is coding and the second is how it should be

crimson foxBOT
#

antoniocantomoniz
Compile Error! Click the errors reaction for more information.
(You may edit your message to recompile.)

foggy jetty
#

Can you show us your preamble?

teal light
#

@foggy jetty
"

#

\documentclass{article}
\usepackage{amsmath} % Para fórmulas matemáticas
\usepackage{cancel} % Para o comando \cancel
\usepackage{xcolor} % Para cores
\usepackage{tikz} % Para personalizar os traços
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

% Redefinir o comando \cancel para usar TikZ com cor no traço
\newcommand\coloredcancel[2][red]{%
\tikz[baseline=(tocancel.base)]{
\node[inner sep=0pt,outer sep=0pt] (tocancel) {$#2$};
\draw[line width=0.8pt,#1] (tocancel.south west) -- (tocancel.north east);
}%
}

\begin{document}

crimson foxBOT
#

antoniocantomoniz
Compile Error! Click the errors reaction for more information.
(You may edit your message to recompile.)

foggy jetty
#

aight thanks ill check it

teal light
foggy jetty
#

fixed it @teal light

#
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{fillbetween} % Load the fillbetween library

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    axis lines=middle,
    xlabel=$x$,
    ylabel=$y$,
    samples=200, % Smooth curves
    domain=-1.5:3,
    ymin=-0.5, ymax=2.5,
    xmin=-2, xmax=3.5,
    axis equal
  ]

    % Lower parabola (1)
    \addplot[name path=parabola1, domain=-1.5:1.5, thick, purple]
      {sqrt(1/2 - x/3)};

    % Upper parabola (2)
    \addplot[name path=parabola2, domain=-1.5:1.5, thick, purple]
      {2/9*x^2 + 3/2};

    % Semi-circle (3)
    \addplot[name path=semicircle, domain=-1:1, thick, purple]
      ({1.5 + sqrt(1 - x^2)}, {1 + x});

    % Vertical line segment (4)
    \addplot[name path=vertical, domain=1:2, draw=none]
      ({-1.5}, {x});

    % Fill the region between curves
    \addplot[gray, opacity=0.3] 
      fill between[
        of=parabola1 and parabola2, 
        soft clip={domain=-1.5:1.5}
      ];

    \addplot[gray, opacity=0.3] 
      fill between[
        of=parabola2 and semicircle, 
        soft clip={domain=1.5:3}
      ];

    % Labels
    \node at (axis cs: -1.5,1.75) [purple, anchor=east] {(4)};
    \node at (axis cs: 0.25,1.95) [purple, anchor=north] {(2)};
    \node at (axis cs: 0.55,0.55) [purple, anchor=north] {(1)};
    \node at (axis cs: 2.5,1.5) [purple, anchor=west] {(3)};

  \end{axis}
\end{tikzpicture}
\end{document}

Use the fillbetween library provided by pgfplots

teal light
#

damm! Thank you so much!
just this one thing, the y axis is set to min -0.5 and max 2.5 but in the graph is still appearing -1 and 3 why?

foggy jetty
teal light
#

still the same

foggy jetty
#

wait

#

How about this?

\begin{axis}[
    axis lines=middle,
    xlabel=$x$,
    ylabel=$y$,
    samples=200,
    domain=-1.5:3,
    ymin=-0.5, ymax=2.5,
    xmin=-2, xmax=3.5,
    axis equal,
    enlargelimits=false, % Prevent automatic range adjustments
    restrict y to domain=-0.5:2.5, % Clip the plotted area
    clip=false, % Prevent extending axes beyond the range
    scaled ticks=false, % Avoid scaling the axis ticks
    ytick={-0.5, 0, 0.5, 1, 1.5, 2, 2.5}, % Set explicit y-ticks
]

Lemme know if this works

teal light
#

i want to not draw the y line so down below

#

like this:

foggy jetty
#

or all the ticks

#

if u dont want

teal light
#

i dont want them but that i know how to remove. Just dont know how to short the line on y on the negative side

foggy jetty
#

to your desired value

teal light
#

i know but when i put the ymin to -0.5 the ymax goes auto to 3 and appears -1 in the graph

#

\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xlabel=$x$,
ylabel=$y$,
samples=200, % curvas Smooth
domain=-1.5:3,
ymin=-0.5, ymax=2.5,
xmin=-3, xmax=3.5,
%xtick = {-(3/2), (3/2)}, ytick = 2,
axis equal,
restrict y to domain=-0.5:2.5, % Clip the plotted area
]

crimson foxBOT
#

antoniocantomoniz
Compile Error! Click the errors reaction for more information.
(You may edit your message to recompile.)

teal light
foggy jetty
#

ok how about

#
\begin{axis}[
    axis lines=middle,
    axis line style={-}, % Normal line style
    xlabel=$x$,
    ylabel=$y$,
    samples=200,
    domain=-1.5:3,
    ymin=-0.5, ymax=2.5, % Set vertical axis limits
    xmin=-2, xmax=3.5,   % Set horizontal axis limits
    scale only axis,     % Prevent extra space for ticks
    enlargelimits=false, % Avoid automatic enlargement
    restrict y to domain=-0.5:2.5, % Clip values outside this range
    clip=false,          % Ensure nothing extra is drawn
    ytick={0, 0.5, 1, 1.5, 2}, % Define custom y-ticks
]
#

it rendered this for me

teal light
#

the image of the graph just got kinda compressed ahahhaha but yes this will work

#

thank you 🙂

foggy jetty
#

welcome. feel free to reach out to me if there are any issues.