9

My MWE:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings, arrows, arrows.meta,patterns.meta}

\tikzset{
    midar/.style 2 args={
        very thick,
        decoration={name=markings,
            mark=at position .55 with {\arrow{latex}},
            mark=at position 0 with {\fill circle (2pt);},
            mark=at position 1 with {\fill circle (2pt);}}
        ,postaction=decorate,
    },
}

\begin{document}
    
    \begin{tikzpicture}[thick]
        \draw[-{Latex}] (0,0) -- (0,5) node[above] {$P$};
        \draw[-{Latex}] (0,0) -- (5,0) node[right] {$V$};
        
        \draw[dashed] (0,4) node[left] {$P_{1}$} -| (1,0) node[below] {$V_{1}$};
        \draw[dashed] (0,1) node[left] {$P_{2}$} -| (4,0) node[below] {$V_{2}$};
        
        \draw (1,4) node[above left]{1};   
        \draw (4,1) node[above right]{2};  
        \draw[midar] (1,4) arc (180:270:3 and 3);
    \end{tikzpicture}
    
\end{document}

This is the picture that I get from the code:

enter image description here

This is an idea for what I'm trying to do:

enter image description here

1
  • 1
    In addition to providing us with code fragments in your question, consider also submitting the complete code that can be compiled to produce the shown output. The complete code is also called as Minimal Working Example (MWE). So we don't need to reassemble your code fragments. Commented May 5, 2021 at 23:50

3 Answers 3

12

Append the following code at the end of the tikzpicture environment

\fill[pattern=north east lines, pattern color=red] (4,0) -- (1,0) -- (1,4) arc (180:270:3 and 3) -- cycle;

Of course, you need to add \usetikzlibrary{patterns} in your preamble.

enter image description here

1
  • Thank you, It worked! Commented May 5, 2021 at 23:52
11

Another possibility if you know the function of your plot you can use fillbetween:

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{arrows.meta,patterns}


\begin{document}

\begin{tikzpicture}
  \begin{axis}[
    xlabel={V},
    ylabel={P},
    yticklabels={,,},
    ytick style={draw=none},
    xticklabels={,,},
    xtick style={draw=none},
    samples=200,
    axis lines=center,
    ymin=0,xmin=0,
    ymax=10,xmax=10,
    no marks,
    every axis x label/.style={
        at={(ticklabel* cs:1.05)},
        anchor=west,
    },
    every axis y label/.style={
        at={(ticklabel* cs:1.05)},
        anchor=south,
    },
    ]
    \addplot[blue,domain=2:4,name path=A] {15*e^(-0.4*x)+2}; %plot
    \addplot[blue,domain=2:3,-Stealth] {15*e^(-0.4*x)+2}; %arrow plot
    \addplot+[black,domain=2:4,name path=B] {0};     % dummy plot
    \addplot+[pattern=north east lines,pattern color=red!60!white] fill between[of=A and B,soft clip={domain=2:4}]; % fillingbetween A and B
    
    \addplot+[dashed,black,domain=0:2] {8.74};
    \addplot+[dashed,black,domain=0:4] {5.03};
    \addplot+[black,ycomb] coordinates {(2, 8.74)};
    \addplot+[black,ycomb] coordinates {(4, 5.03)};
    
    \coordinate (m1) at (axis cs:2,8.74); %mark1
    \coordinate (m2) at (axis cs:4,5.03); %mark2

       
  \end{axis}

    \filldraw[fill=blue,draw=blue] (m1) circle(0.05) node[above] {\small 1};
    \filldraw[fill=blue,draw=blue] (m2) circle(0.05) node[right] {\small 2};


\end{tikzpicture}
\end{document}

enter image description here

1
  • Disclaimer: I only upvote correct answers accompanied with complete code. Commented May 6, 2021 at 2:51
5

Edit: corrected function domain, added declared function f(x) and added missed elements of diagram.

A variation of @Roland answer with use of the patterns.meta library and a wee bit shorter code:

\documentclass[border=3.141592]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{arrows.meta,
                decorations.markings,
                patterns.meta}

\begin{document}
    \begin{tikzpicture}[
->-/.style = {decoration={%
    name=markings,
         mark=at position 0.5 with {\arrow{Stealth}}},
    postaction=decorate},
dot/.style = {circle, fill=blue, inner sep=0pt, minimum size=4pt,
              node contents={}},
                        ]
\begin{axis}[
declare function = {f(\x)=(12*e^(-1.4*\x)+1);},    
    axis lines=middle,
    xlabel=$V$, x label style={anchor=west},
    ylabel=$P$, y label style={anchor=south},
    xtick=\empty,
    ytick=\empty,
    xmin=0, xmax=5,
    ymin=0, ymax=5,
    clip=false,
    domain=1:4,
    every axis plot post/.append style={very thick, blue}
    ]
\addplot [name path=A] {f(x)}; %plot
\addplot [draw=none, name path=B] {0}; % x-domain
\addplot +[pattern={Lines[angle=45,distance={3pt}, line width=0.2pt]},
           pattern color=red] 
        fill between[of=A and B]; % patterns
\addplot [->-] {f(x)}; % for arrow on the middle of curve
%
\draw[densely dashed] (0,{f(1)}) node[left] {$P_1$} 
        -| (1,0) node[below] {$V_1$}    node[pos=0.5,dot,dot,label=1];
\draw[densely dashed] (0,{f(4)}) node[left] {$P_2$} 
        -| (4,0) node[below] {$V_2$}    node[pos=0.5,dot,dot,label=2];
\end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

7
  • Disclaimer: I only upvote correct answers accompanied with complete code. Commented May 6, 2021 at 2:51
  • 1
    @Kim : Good to know! ;-)
    – AlexG
    Commented May 6, 2021 at 7:09
  • @AlexG: Double upvotes for answers with animate. :-) Commented May 6, 2021 at 7:30
  • @Kim : I knew you would have multiple accounts :-D
    – AlexG
    Commented May 6, 2021 at 7:35
  • @AlexG: Considering your expertise, I believe you can create a special PSTricks package for drawing stereometry as what I asked in this question. :-) Commented May 6, 2021 at 7:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .