1

I am working on a thermodynamic course. I want to draw an isothermal curve in the diagram of clapeyron and try this with the code below:

isothermal transformation

I want to draw on the curve a colored surface between the point x = 3 and x = 6?

I want to add a arrow indicating the sense of direction of transformation from?

I'm using this code:

\documentclass[margin=10pt]{standalone}
\usepackage{pgfplots}
\usepackage{amsmath}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\tikzset{fleche/.style args={#1:#2}{ postaction = decorate,decoration={name=markings,mark=at position #1 with {\arrow[#2,scale=2]{>}}}}}
\begin{axis}[
    axis x line=bottom,
    axis y line=left,
    xmin=0, xmax=10, 
    ymin=0, ymax=10,
    xlabel={Volume $(m^3)$},
    ylabel={Pression $Pa$},
    ytick=\empty,
   % extra y ticks={8},
    extra y tick style={align=center, font=\scriptsize},
    %extra y tick labels={normal\\health},
    extra y ticks={1.5,6},
    extra y tick labels={$\text{P}_\text{1}$,$\text{P}_\text{2}$},
    xtick=\empty,
    extra x ticks={3,6},
    extra x tick labels={$\text{V}_\text{1}$,$\text{V}_\text{2}$},
    ]
    \addplot[dashed, domain=0:3] {6};
    \addplot[dashed, domain=0:6] {1.5};

    \draw (axis cs:3,6) to [bend right=30]
        coordinate[pos=0] (B') coordinate[pos=0.17] (B) coordinate[pos=0.6] (B'') (axis cs:6,1.5);
     \addplot[color=red,fill=red, pattern=north east lines,  domain=3:6,samples=100] {6} \closedcycle;
     \addplot+[mark=none,domain=3:6,fill=blue!20!white] {axis cs:6,0;axis cs:3,6} \closedcycle;
    \draw[dashed, thin] (axis cs:6,1.5) -- (axis cs:6,0);
    \draw[dashed, thin] (axis cs:3,6) -- (axis cs:3,0);
\end{axis}
\end{tikzpicture}

\end{document}
  • Could you please explain the first question? Which surface? – caverac Jan 17 '18 at 11:08
  • Welcome to TeX.SX! I also don't know what you exactly want to achieve. Could you sketch on your diagram what you want to do and/or modify the text, please!? – Stefan Pinnow Jan 17 '18 at 14:08
  • i want to draw the geometrical surface between the axis x=V1 and x=V2, of this function, but, i don't have any expression P=f(V), so i use list of points axis cs:6,1.5 .. i want to explain to my students the work can be considered like a surface , in the clapeyron diagram. for this raison i want to colorate the integrated surface of P=f(V) between V1 to V2 – moradov Jan 17 '18 at 14:32
  • Please don't use \text like this, that command does not do what you think, and _\text is equally as bad even if it works in this case. Use mathrm or textup instead. This wrong use of \text is a very common error, and visitors should preferably not be encouraged to use it like this. Btw why \text{1}? – daleif Jan 17 '18 at 19:53
7

Revised answer (using PGFPlots v1.16)

With the release of the PGFPlots v1.16 it is now possible to use pgf declared constants/functions almost everywhere. With that it is now easy to draw the real P-V-curve as well as the corresponding axis ticklabels very easily.

For details please have a look at the comments in the code.

% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \usetikzlibrary{
        decorations.markings,
    }
    \tikzset{
        fleche/.style args={#1:#2}{
            postaction=decorate,
            decoration={
                name=markings,
                mark=at position #1 with {\arrow[#2,scale=2]{>}}
            },
        },
    }
    \pgfplotsset{
        % use this `compat' level or higher, so TikZ coordinates don't have to
        % be prefixed with `axis cs:'
        compat=1.11,
        % define some values and functions to "automatically" draw the
        % desired plot afterwards, regardless of the values
        % (only the values for `xmax' and `ymax' have to be adjusted accordingly)
        % ideal gas law: P V = n R T = const
        /pgf/declare function={
            % define V1, V2 and P1
            Vone = 3;
            Vtwo = 6;
            Pone = 6;
            % calculate constant nRT
            nRT = Vone * Pone;
            % now any P can be calculated for a given V
            P(\V) = nRT/\V;
            % for simplicity of later use already calc P2 here and assign the
            % result to a constant
            Ptwo = P(Vtwo);
        },
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis x line=bottom,
        axis y line=left,
        xmin=0,xmax=10,
        ymin=0,ymax=10,
        % the ticks can be positioned at the declared constants "automatically"
        xtick={Vone,Vtwo},
        xticklabels={$V_1$,$V_2$},
        ytick={0,Ptwo,Pone},
        yticklabels={0,$P_2$,$P_1$},
        axis on top,
    ]

        % fill the area below the curve
        % (draw it first, so it is below everything else)
        \addplot [
            draw=none,
            fill=red!40,
            % the declared constants can also be used here
            domain=Vone:Vtwo,
        ] {P(x)}
            \closedcycle
        ;

        % now draw the curve with the arrow on the line
        \addplot [
            thick,
            domain=Vone:Vtwo,
            fleche={0.6:red},
        ] {P(x)}
            coordinate [pos=0] (start)
            coordinate [pos=1] (end)
        ;

        % draw dashed lines and start and end points
        % (and here the declared constants can be used as well)
        \pgfplotsforeachungrouped \point in {start,end} {
            \edef\temp{
                \noexpand\draw [dashed]
                    (\pgfkeysvalueof{/pgfplots/xmin},0 |- \point) --
                    (\point) circle (2pt) --
                    (0,\pgfkeysvalueof{/pgfplots/ymin} -| \point);
                \noexpand\fill (\point) circle (2pt);
            }\temp
        }

    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

Original answer (using PGFPlots v1.15)

I edited my answer after you have shown in your answer what you really wanted the plot look like. For details please have a look at the comments in the code.

% used PGFPlots v1.15
\documentclass[border=5pt]{standalone}
\usepackage{amsmath}
\usepackage{pgfplots}
    \usetikzlibrary{
        decorations.markings,       % <-- missed to load
    }
    \tikzset{
        fleche/.style args={#1:#2}{
            postaction=decorate,
            decoration={
                name=markings,
                mark=at position #1 with {\arrow[#2,scale=2]{>}}
            },
        },
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis x line=bottom,
        axis y line=left,
        xmin=0, xmax=10,
        ymin=0, ymax=10,
%        % (made labels more common)
%        % (because of the "sketch" type of the plot these should not be needed)
%        xlabel={Volume $(\mathrm{m}^3)$},
%        ylabel={Pressure (Pa)},
        % (changed ticks + labels to normal ticks instead of extra ticks)
        xtick={3,6},
        xticklabels={$V_1$,$V_2$},
        ytick={1.5,6},
        yticklabels={$P_2$,$P_1$},  % <-- (changed order of entries)
    ]
        % fill the area below the curve
        % (draw it first, so it is below everything else)
        \fill [
            red!40,
        ]
            (axis cs:3,6) to [bend right=30]
            (axis cs:6,1.5) |-
            (axis cs:3,\pgfkeysvalueof{/pgfplots/ymin}) --
            cycle
        ;

        % draw the dashed lines
        % (using two different approaches)
        \addplot [dashed,domain=0:3,samples=2] {6};
        \addplot [dashed,domain=0:6,samples=2] {1.5};

        \draw [dashed,thin] (axis cs:6,1.5) -- (axis cs:6,0);
        \draw [dashed,thin] (axis cs:3,6)   -- (axis cs:3,0);

        % now draw the curve
        \draw [
            fleche={0.6:red},
            thick,              % <-- added
        ] (axis cs:3,6) to [bend right=30]
            % store start and end coordinates
            coordinate [pos=0] (start)
            coordinate [pos=1] (end)
        (axis cs:6,1.5);

        % draw start and end point
        \fill [radius=2pt]
            (start) circle[]
            (end)   circle[];
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

1

p V = n k T = const

\documentclass[border=5pt]{standalone}
\usepackage{amsmath}
\usepackage{pgfplots}
    \usetikzlibrary{
        decorations.markings,       
        patterns,
    }
    \tikzset{
        fleche/.style args={#1:#2}{
            postaction=decorate,
            decoration={
                name=markings,
                mark=at position #1 with {\arrow[#2,scale=2]{>}}
            },
        },
    }
\begin{document}\begin{tikzpicture}
\tikzset{fleche/.style args={#1:#2}{ postaction = decorate,decoration={name=markings,mark=at position #1 with {\arrow[#2,scale=2]{>}}}}}
\begin{axis}[
    axis x line=bottom,
    axis y line=left,
    xmin=0, xmax=10, 
    ymin=0, ymax=10,
    xlabel={Volume $(m^3)$},
    ylabel={Pression $Pa$},
    ytick=\empty,
   % extra y ticks={8},
    extra y tick style={align=center, font=\scriptsize},
    %extra y tick labels={normal\\health},
    extra y ticks={1.5,6},
    extra y tick labels={$P_1$,$P_2$},
    xtick=\empty,
    extra x ticks={3,6},
    extra x tick labels={$V_1$,$V_2$},
    ]
    \addplot[dashed, domain=0:3] {6};
    \addplot[dashed, domain=0:6] {1.5};

%     \draw (axis cs:3,6) to [bend right=30]
%         coordinate[pos=0] (B') coordinate[pos=0.17] (B) coordinate[pos=0.6] (B'') (axis cs:6,1.5);
    \addplot [domain=3:6,fill=red, pattern=north east lines] (\x,{6/(\x-2)})\closedcycle;
    \draw[dashed, thin] (axis cs:6,1.5) -- (axis cs:6,0);
    \draw[dashed, thin] (axis cs:3,6) -- (axis cs:3,0);
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • thank you very much for your quick reply, by two this answers i can draw my figure – moradov Jan 17 '18 at 16:46
  • Btw: please don't use the \text command like that. I know the op did and I'll comment there as well. Otherwise +1 for a good answer – daleif Jan 17 '18 at 19:49
  • 1
    @daleif Done. I did not pay any attention to this. The only purpose of this post was that one does not have to guess the curve, nor fake it, but just open a random book on thermodynamics. – user121799 Jan 17 '18 at 20:18
-2

Thank you, I got to that I want

enter image description here

by modifying the first code

% used PGFPlots v1.15
\documentclass[border=5pt]{standalone}
\usepackage{amsmath}
\usepackage{pgfplots}
    \usetikzlibrary{
        decorations.markings,       % <-- missed to load
        patterns,
    }
    \tikzset{
        fleche/.style args={#1:#2}{
            postaction=decorate,
            decoration={
                name=markings,
                mark=at position #1 with {\arrow[#2,scale=2]{>}}
            },
        },
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis x line=bottom,
        axis y line=left,
        xmin=0, xmax=10,
        ymin=0, ymax=10,
%        % (made labels more common)
%        % (because of the "sketch" type of the plot these should not be needed)
%        xlabel={Volume $(\mathrm{m}^3)$},
%        ylabel={Pressure (Pa)},
        % (changed ticks + labels to normal ticks instead of extra ticks)
        xtick={3,6},
        xticklabels={$V_1$,$V_2$},
        ytick={1.5,6},
        yticklabels={$P_2$,$P_1$},  % <-- (changed order of entries)
    ]
        % fill the area below the curve
        % (draw it first, so it is below everything else)
        \fill [
            red!40,
        ]
            (axis cs:3,6) to [bend right=30]
            (axis cs:6,1.5) |-
            (axis cs:3,\pgfkeysvalueof{/pgfplots/ymin}) --
            cycle
        ;

        \addplot [dashed, domain=0:3] {6};
        \addplot [dashed, domain=0:6] {1.5};

        \draw [
            fleche={0.6:red},
            thick,              % <-- added
        ] (axis cs:3,6) to [bend right=30]
        (axis cs:6,1.5);
         \node[coordinate, pin=+30:{W=surface}, anchor=center,fill=red,circle,scale=0.3]at (axis cs:4.0,2.3){};
        \draw [dashed, thin] (axis cs:6,1.5) -- (axis cs:6,0);
        \draw [dashed, thin] (axis cs:3,6)   -- (axis cs:3,0);
    \end{axis}
\end{tikzpicture}
\end{document}
  • 2
    Instead of writing your own answer which is basically the same as mine (except for the superfluous stuff that was unclear in your question), please consider upvoting (by clicking on the arrows next to the score) and/or marking it as the accepted answer (by clicking on the checkmark ✓). – Stefan Pinnow Jan 18 '18 at 7:39

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.