# Plotting a PV function graph

I'm trying to plot the following graph in LaTeX, but I cannot, for the life of me, find mathematical functions that work. This is my code and the following image is what I'm trying to achieve:

    \begin{figure}
\centering
\begin{tikzpicture}
\def\myfirstfunction{(\x - 4.65) / ((\x - 4.65) * (\x + 0.35)) - 0.2}
\def\mysecondfunction{(\x - 6) / ((\x - 4.65) * (\x + 0.35)) - 0.2}
\begin{axis}[
xlabel={Volume},
ylabel={Pression},
axis lines=middle,
scaled ticks=false,
xtick=\empty, % Remove x-axis ticks
ytick=\empty, % Remove y-axis ticks
grid=none,
width=10cm,
height=8cm,
xmin=0, % Set x-axis minimum to 0
xmax=5, % Adjust domain to show only the first quadrant
ymin=0, % Set y-axis minimum to 0
ymax=2.5,  % Adjust range to show only the first quadrant
xlabel style={at={(ticklabel* cs:1)},anchor=north west}, % Place xlabel to the bottom
ylabel style={at={(ticklabel* cs:1)},anchor=south east,rotate= 0} % Place ylabel to the left
]
\addplot[domain=0.1:5,samples=100,smooth,blue] {\myfirstfunction}; % Plot function
\addplot[domain=0.1:5,samples=100,smooth,magenta] {\mysecondfunction}; % Plot second function
\end{axis}
\end{tikzpicture}
\caption{Graph of $y = \frac{x - 4.65}{(x - 4.65)(x + 0.35)} - 0.2$ and $y = \frac{1}{x} + 1$ in the first quadrant}
\label{fig:graph}
\end{figure}


Any help is greatly appreciated

• Welcome to TeX.SX! If you don't have particular curves in mind (in this case you'd need to give some more details), start from \def\myfirstfunction{7.5/(\x+2)} and \def\mysecondfunction{2.5/\x}. I think the curves are defined by PV=const., i.e., P=const/V. Feb 12 at 19:25

## 1 Answer

Looks like you're intermixing Tikz and pgfplots ?

Here's an approach which draws those curves qualitatively with a high degree of control. Basic ideas:

• just draw lines, where you bend two of them using to[out=,in=]
• use self-defined styles to simplify work and code

Let's go through some details. I suggest to look up details in the pgfmanual in parallel.

### Drawing lines

For example the x-axis starts at (0,0) \draw[->] (0,0) -- +(8,0); and moves +(8,0) to the side. It's a relative motion, and in this case there's no difference to using (0,8). However, once your starting point is somewhere else, it's a very nice feature to use.

The option [->] simply says: "draw a line between both points, have no symbol for the starting point, and an arrow at its end.

### Adding text in one go

Tikz follows a path-concept. I.e. you start a path by \ and end it by a ; and everything in between are so called actions (do this!) .

So extending the previous command into

\draw[->] (0,0) -- +(8,0) node[anchor=north,yshift=-3mm]{Volume};


means:

• start \ (what?) to draw
• connect points as said before [->]
• when reaching the end point (8,0) add a node
• instead of referring its position to its center (default) use its upper edge anchor=north
• also do some shifts
• put some text at its position {Volume}
• finally end this path ;

### The curves

Two of them are just straight lines, following the same approach as above.

The other two are bend. For easy control you replace the -- by to[out=in=] while specifying suitable angles.

Again for the curves text some nodes are added into the pathes.

### Styles / formats

Put all you need at the beginning of the tikzpicture environment; change only here to change the whole drawing:

 \begin{tikzpicture}[
>={Stealth},                        % nicer arrow tip
lw/.style  ={line width=1.5pt},     % line width for all
isob/.style={dashed,draw=brown,lw}, % reusing line width lw
isom/.style={dotted,draw=blue,lw},
adia/.style={green,lw},
isot/.style={dashed,draw=blue!80!yellow!50,lw},
]


### Outlook

Using class standalone is useful, as you can generate those drawing separately. In your target document you can use \includgraphics from package graphicx to include this image as pdf, i.e. as vector graphic.

\documentclass[10pt,border=3mm,tikz]{standalone}
\usetikzlibrary{arrows.meta}

\begin{document}
\begin{tikzpicture}[
>={Stealth},                        % nicer arrow tip
lw/.style  ={line width=1.5pt},     % line width for all
isob/.style={dashed,draw=brown,lw}, % reusing line width lw
isom/.style={dotted,draw=blue,lw},
adia/.style={green,lw},
isot/.style={dashed,draw=blue!80!yellow!50,lw},
]
% ~~~ a coordinate ~~~~
\coordinate (A) at (1.5,6.5);

% ~~~ axes ~~~~~~~~~~
\draw[->] (0,0) -- +(8,0) node[anchor=north,yshift=-3mm]{Volume};
\draw[->] (0,0) -- +(0,8) node[anchor=north east,xshift=-3mm]{Pressure};

% ~~~ curves ~~~~~~~~~~
\draw[isob] (A) -- +(5,0) node[anchor=south,pos=0.5]{isobaric};
\draw[isom] (A) -- +(0,-4.5) node[anchor=south west]{isometric};
\draw[adia] (A) to[out=-80,in=160]
+(3,-4.5) node[yshift=7mm,text=black]{adiabatic};
\draw[isot] (A) to[out=-60,in=170]
+(4.5,-3) node[text=black,yshift=8mm,xshift=-5mm]{isothermal};

\end{tikzpicture}
\end{document}

• THANK YOU, this works perfectly like I need it to Feb 12 at 20:54