# How to plot a function

Hello I am new to this stackexchange, and I have a question in regards to how one plots a function. I have done research, and I have seen this question:

The Question

I have even tried programming it but it does not come up, and the function I would like to graph, and generally learn how to plot any function is the sqrt(9-x)^.5

Here is the bit of code which I have been working on:

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphics}
\usepackage{graphicx}
\usepackage{pgfplots}
\usepackage{subfigure}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{subfigure}

\begin{figure}
\centering
\subfigure
{
\begin{tikzpicture}
\begin{axis}[xmin=-1.5,ymin=-1.5,ymax=1.5]
\addlegendentry{$f(x)=\sqrt{x}$}
\end{axis}
\end{tikzpicture}
}
%
\end{figure}


Thank you very much.

• (1) welcome, (2) It will be beneficial to others if you extend this to a full by minimal document. Then it is easier to for example verify that you have loaded the necessary packages in you preamble for this example to work Feb 11, 2019 at 20:20
• @marmot its the \sqrt{9-x} Feb 11, 2019 at 21:35
• @daleif There are all the packages Feb 11, 2019 at 21:39
• That is not a minimal example, there is no documentclass and no begin/end document Feb 11, 2019 at 21:42

Welcome to TeX.SE! This is an attempt to summarize some aspects of the comments by @daleif and myself.

1. You got an empty plot because you set ymax=1.5 but the function assumes larger values in the domain you are plotting it, so you effectively clip the plot away.
2. You are using the subfigure package. It is generally recommended to use the subcaption package instead.
3. Your code does not quite make an MWE. As pointed out by @daleif, it is lacking a \documentclass as well as \begin{document} and \end{document}. And you are loading packages multiple times, and pgfplots already loads tikz, which loads graphicx.

This qualifies as a MWE and takes into account the above points.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{subcaption}
\begin{document}
\begin{figure}[htb]
\centering
\begin{subfigure}{0.5\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[xmin=-0.1,xmax=1.6,ymin=1.5,ymax=3.5,
xlabel={$x$},ylabel={$f(x)$}]
\addlegendentry{$f(x)=\sqrt{9-x}$}