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

  • Context: MHB 
  • Thread starter Thread starter karush
  • Start date Start date
Click For Summary
SUMMARY

This discussion focuses on enhancing a TikZ plot of the square root function, specifically addressing shading under the curve and customizing axis appearance. Users can shade the area between the curve and the x-axis by adding the command \addplot[fill=cyan!30, draw=none, domain=0:4] {sqrt(x)} \closedcycle;. To remove arrows from the axes, the axis lines*=middle option is recommended. The \end{axis} command concludes the axis environment at the specified xmax value of 5. Additionally, users can customize ticks using xtick={1,2,3,4} and ytick=\empty.

PREREQUISITES
  • Familiarity with TikZ and PGFPlots packages in LaTeX
  • Understanding of plotting functions in LaTeX
  • Knowledge of LaTeX syntax for commands and environments
  • Basic concepts of graphing mathematical functions
NEXT STEPS
  • Explore advanced TikZ features for creating complex plots
  • Learn about customizing plot styles in PGFPlots
  • Investigate the use of \addplot for various fill options
  • Study the documentation for PGFPlots to understand all available options
USEFUL FOR

Mathematicians, educators, and researchers who utilize LaTeX for creating visual representations of mathematical functions, as well as anyone looking to enhance their TikZ plotting skills.

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 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · 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