I'd like to draw a closed plot path filled with pattern and surrounded by arrows:
When I used @Jake's solution to add arrows (Decorate a path with little arrows parallel to it) then the pattern made with the method proposed by @Domenico Camasta vanishes (Modified pattern does not see the pattern color option). The command postaction=decorate causes that the pattern filling the area is not created.
- What can I do to avoid executing 2-times the \addplot for the same path in the code below?
- Why removing of enlargelimits=true affects the distance between arrows and the plot path?
- How to trim both axes at the origin of the coordinate system?
The code is following:
\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=newest}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{patterns}
\usepgfplotslibrary{fillbetween}
\definecolor{mygreen}{rgb}{0.00000,0.60000,0.00000}
\makeatletter
\pgfdeclarepatternformonly[\LineSpace]{my north east lines}%
{\pgfqpoint{-1pt}{-1pt}}%
{\pgfqpoint{\LineSpace}{\LineSpace}}%
{\pgfqpoint{\LineSpace}{\LineSpace}}%
{\pgfsetcolor{\tikz@pattern@color}
\pgfsetlinewidth{0.4pt}
\pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
\pgfpathlineto{\pgfqpoint{\LineSpace + 0.1pt}{\LineSpace + 0.1pt}}
\pgfusepath{stroke}
}
\makeatother
\newdimen\LineSpace
\tikzset{
line space/.code={\LineSpace=#1},
line space=9pt
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
width=10cm,
height=7cm,
axis on top=true,
axis x line=middle,
axis y line=middle,
xtick=\empty,
ytick=\empty,
extra x ticks={0,0.1},
extra x tick labels={$x_{min}$,$x_{max}$},
extra y ticks={600},
extra y tick labels={$F_{max}$},
extra y tick style={yticklabel style={xshift=0.8ex, anchor=west}},
xlabel={piston position},
ylabel={force},
enlargelimits=true
]
\addplot[
name path=A,color=blue,solid,forget plot,smooth,
decoration={
markings,
mark=between positions 0.1 and 1 step 3em with {\draw [-latex] (-2mm,0) -- (2mm,0);},
raise=0.6cm
},
postaction=decorate
]
table[row sep=crcr]{%
0 60\\
0.005 450\\
0.025 550\\
0.1 600\\
} node [above=0.8ex,pos=0.96] {$F_{\rightarrow}(x)$};
\addplot[
name path=B,color=mygreen,solid,forget plot,smooth,
decoration={
markings,
mark=between positions 0.1 and 1 step 3em with {\draw [-latex] (-2mm,0) -- (2mm,0);},
raise=0.6cm
},
postaction=decorate
]
table[row sep=crcr]{%
0.1 600\\
0.095 200\\
0.065 100\\
0 60\\
} node [below=1.0ex,pos=0.93] {$F_{\leftarrow}(x)$};
\addplot fill between[of=A and B,
split,
every segment no 1/.style={pattern=my north east lines,pattern color=gray}
];
\node[fill=white] at (0.05,350) {\textcolor{gray}{dissipated energy}};
\end{axis}
\end{tikzpicture}
\end{document}