5

How would you draw a graph in latex that looks like below? Something that looks almost hand drawn but still Latex generated.

desired output

Please note that I do not care about axes labels in this question.

I have included the graph template code below, where I want to draw such graph.

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usepgfplotslibrary{fillbetween}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
% !TeX spellcheck = en_GB 
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
grid=major,
%ticks=none,
xmin=-0.4,
xmax=6.5,
ymin=-1,
ymax=11,
xtick={0,1,2,3,4,5,6},
ytick={0,2.5,5,7.5,10},
height=9cm,
width=12cm,
axis line style={shorten >=-10pt, shorten <=-10pt},
ylabel style={
    anchor=south,
    at={(ticklabel* cs:1.0)},
    yshift=10pt
},
ylabel=y,
xlabel style={
    anchor=west,
    at={(ticklabel* cs:1.0)},
    xshift=10pt
},
xlabel=x,
axis line style={shorten >=-10pt, shorten <=-10pt},
yticklabel style={
    fill=white,
    %yshift=10pt,
},
xticklabel style={
    %xshift=10pt,
    fill=white
}
]
\end{axis}
\end{tikzpicture}
\end{document}

Thank you

7

Here is a proposal: build up list and plot it smoothly. Of course, you can adjust the step (it is 0.5 in the example below) and the amplitude (1.5 in the example below).

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usepgfplotslibrary{fillbetween}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
% !TeX spellcheck = en_GB 
\foreach \X [count=\Y] in {0,0.5,...,6}
{\ifnum\Y=1
\pgfmathsetmacro{\myrnd}{10*rnd}
\xdef\myrnd{\myrnd}
\xdef\Lst{(\X,\myrnd)}
\else
\pgfmathsetmacro{\myrnd}{\myrnd+1.5*(rnd-0.5)}
\xdef\myrnd{\myrnd}
\xdef\Lst{\Lst (\X,\myrnd)}
\fi
}
\typeout{\Lst}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
grid=major,
%ticks=none,
xmin=-0.4,
xmax=6.5,
ymin=-1,
ymax=11,
xtick={0,1,2,3,4,5,6},
ytick={0,2.5,5,7.5,10},
height=9cm,
width=12cm,
axis line style={shorten >=-10pt, shorten <=-10pt},
ylabel style={
    anchor=south,
    at={(ticklabel* cs:1.0)},
    yshift=10pt
},
ylabel=y,
xlabel style={
    anchor=west,
    at={(ticklabel* cs:1.0)},
    xshift=10pt
},
xlabel=x,
axis line style={shorten >=-10pt, shorten <=-10pt},
yticklabel style={
    fill=white,
    %yshift=10pt,
},
xticklabel style={
    %xshift=10pt,
    fill=white
}
]
\addplot[smooth] coordinates {\Lst};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.