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

  • Thread starter Thread starter karush
  • Start date Start date
AI Thread Summary
The discussion focuses on enhancing a TikZ plot of the square root function. Key points include methods to shade the area between the curve and the x-axis, which can be achieved by adding a specific plot command. Participants also address the removal of arrows from the axis by using a modified axis line specification. Clarifications are provided regarding the endpoint of the axis, confirming it ends at the specified xmax value. Overall, the conversation revolves around improving the visual presentation of the plot for a LinkedIn post.
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...
 
Physics news 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
Views
2K
Replies
8
Views
2K
Replies
2
Views
2K
Replies
7
Views
2K
Replies
2
Views
1K
Replies
0
Views
5K
  • Poll Poll
Replies
11
Views
3K
Replies
5
Views
4K
Back
Top