Just sqrt(x) with 1,2,3,4 ticks

  • Context: MHB 
  • Thread starter Thread starter karush
  • Start date Start date
karush
Gold Member
MHB
Messages
3,240
Reaction score
5
\begin{tikzpicture}[scale=1]
%preamble \usepackage{pgfplots}
\begin{axis}[xmin=-1, xmax=5, ymin=-1, ymax=3, axis lines=middle, ticks=none]
\addplot[
draw = blue, smooth, ultra thick,
domain=0:4,
] {sqrt(x)}
foreach \x in {1,2,3,4} { (axis cs:{\x},0) node[below left] {\x} };
\end{axis}
\end{tikzpicture}

1. how do I shade between the curve and x-axis on [0,4]
2. I don't need the arrows on the axis
3 where does \end{axis} actually end?
4. suggestions...

looked at various samples but there was a lot of versions
going to post this with a problem on LinkedIn so trying to make it look the best
however don't think they render tikz and probably not script ,,,, maybe
its all new to me
thanks ahead...
 
on Phys.org
karush said:
1. how do I shade between the curve and x-axis on [0,4]
2. I don't need the arrows on the axis
3 where does \end{axis} actually end?
4. suggestions...
1. We can add \addplot[fill=cyan!30, draw=none, domain=0:4] {sqrt(x)} \closedcycle; to shade the curve up to $x=4$.
2. If we specify axis lines*=middle with a star (*) then the arrows are omitted.
3. The axis ends at $x=5$ because that was specified with xmax=5.
4. We can use xtick={1,2,3,4}, ytick=\empty instead of ticks=none and a foreach to draw ticks.

\begin{tikzpicture}[scale=1]
%preamble \usepackage{pgfplots}
\begin{axis}[xmin=-1, xmax=5, ymin=-1, ymax=3, axis lines*=middle, xtick={1,2,3,4}, ytick=\empty]
\addplot[fill=cyan!30, draw=none, domain=0:4] {sqrt(x)} \closedcycle;
\addplot[
draw = blue, smooth, ultra thick,
domain=0:4,
] {sqrt(x)};
\end{axis}
\end{tikzpicture}
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 0 ·
Replies
0
Views
6K
  • Poll Poll
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K