# Linear plot as pgf plot

Is that possible to draw a linear plot using pgf plot function? I dont want to add numerical data inside the plot. I want to show a linear relation of two different quantities as a plot. Just imagine, from an origin (0,0) one line moving towards north east direction at 45 degree with x axis.

\documentclass[hidelinks, 12pt, a4paper, oneside]{book}
\usepackage{pgfplots}
\usepgfplotslibrary{external}

\tikzexternalize
\pgfplotsset{plot coordinates/math parser=false}
\usepgfplotslibrary{units}
\begin{document}

\begin{figure}[h!]
\begin{center}
\begin{tikzpicture}
\begin{axis}[
width=\linewidth,
grid=major,
grid style={dashed,gray!30},
xlabel=X Axis $l$,
ylabel=Y Axis $R$,
x unit=\si{\meter},
y unit=\si{\ohm},
legend style={at={(0.5,-0.2)},anchor=north},
x tick label style={rotate=90,anchor=east}
]
% What should I add here for a result as I want?
\legend{Plot}
\end{axis}
\end{tikzpicture}
\caption{My pgf plot.}
\end{center}
\end{figure}

\end{document}


Just plot x. With axis equal or axis equal image you make sure that the slope matches.

\documentclass[hidelinks, 12pt, a4paper, oneside]{book}
\usepackage{siunitx}
\usepackage{pgfplots}
\usepgfplotslibrary{external}

\tikzexternalize
\pgfplotsset{plot coordinates/math parser=false}
\usepgfplotslibrary{units}
\begin{document}

\begin{figure}[h!]
\begin{center}
\begin{tikzpicture}
\begin{axis}[axis equal image,
width=\linewidth,
grid=major,
grid style={dashed,gray!30},
xlabel=X Axis $l$,
ylabel=Y Axis $R$,
x unit=\si{\meter},
y unit=\si{\ohm},
legend style={at={(0.5,-0.2)},anchor=north},
x tick label style={rotate=90,anchor=east}
]
% What should I add here for a result as I want?
\legend{Plot}
\end{axis}
\end{tikzpicture}
\caption{My pgf plot.}
\end{center}
\end{figure}

\end{document}


For general slopes multiply x by the tangent of the slope angle. In this case this would be

 \addplot[domain=0:5,samples=2] {tan(45)*x};


but you can adjust 45 to your angle in the general case.

• Ty for your answer. How can erase all the numbers from axis? – Mannie Apr 10 at 15:44
• @Mannie Add enlargelimits=false, to the options of the axis. – user194703 Apr 10 at 15:45
• Can I somehow reduce the length of line? I mean plot length... – Mannie Apr 10 at 18:08
• @Mannie Just add width=5cm, say, to the options of the axis to set its width to 5cm. – user194703 Apr 10 at 18:09
• In your picture, maximum point is (5,5), I want that as (4.5,4.5).. Sorry for wrong representation of my query. – Mannie Apr 10 at 18:17