Torbjørn fant løsningen =)
Torbjørn skrev:Veit ikkje akkurat kvifor, men om du endrer y=-0.5cm til y=0.5cm mot slutten av axis-innstillingane er det tilbake slik det skal vere. \hspace{-0.75ex} må og fjernast, jfr. kommentaren til Jake.
Kode: Velg alt
\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\usepackage{amsmath}
\begin{document}
\pgfplotsset{
shift down/.style={
y filter/.code={\pgfmathparse{\pgfmathresult*(#1)}}
},
shift down/.default=1,
every axis plot post/.style={restrict y to domain=0.5:inf},
positive/.style={
no markers,
red
},
negative/.style={
no markers,
blue
},
/tikz/function label/.style={
anchor=east
},
step functionallinenumber/.code={
\stepcounter{functionallinenumber}
},
title entries/.initial={}
}
\makeatletter
\newcommand\functionalline[4][\@empty]{
\edef\plots{
\noexpand\addplot [negative, shift down=#3, forget plot] {#2<0};
\noexpand\addplot [positive, shift down=#3, forget plot] {#2>0};
}
\plots
\node at (axis cs:\pgfkeysvalueof{/pgfplots/xmin},#3) [function label] {%
\ifx#1\@empty%
$#2$%
\else%
$#1$%
\fi
};
\pgfplotsinvokeforeach {#4} {
\node at (axis cs:##1,#3) [
fill=white,
inner sep=1pt,
declare function={x=##1;} % Set 'x' to current position
] {%
\pgfkeys{/pgf/fpu}% Use the fpu library, because it doesn't throw an error for divide by zero, but sets result to +/- inf
\pgfmathparse{#2}%
\pgfmathfloatifflags{\pgfmathresult}{0}{0}{x}% Check whether result is zero.
\pgfkeys{/pgf/fpu=false}%
};
}
}
\newenvironment{functionallines}[3][]{
\begin{tikzpicture}
\begin{axis}[
extra x ticks = {#2},
grid=none,
xticklabel pos=right,
hide y axis,
x axis line style={draw=none},
every tick label/.style={
anchor=base,
yshift=1ex,
gray!50
},
every extra x tick/.style={
every tick label/.style={
anchor=base,
yshift=1ex,
inner xsep=0pt,
fill=white,
text=black
}
},
extra x tick style={grid=major},
xtick pos=right,
major tick length=0pt,
enlarge x limits=false,
enlarge y limits={abs=0.75},
domain=#3,
samples=100,
y dir=reverse, y = 0.5cm,
clip=false,
#1
]
}{
\coordinate (bottom right) at (rel axis cs:1,0);
\coordinate (top right) at (rel axis cs:1,1);
\end{axis}
\draw [-latex] (top right-|current bounding box.west) -- (top right) node [right] {$x$};
\draw (bottom right) -- (bottom right-|current bounding box.west);
\end{tikzpicture}
}
\begin{functionallines}[
extra x tick labels={$\sqrt{5}$,$\pi$,$2\pi$},
xtick={0,1,4,5}]{2.23,3.14,6.3}{0:6.5}
\functionalline[x-\sqrt{5}]{x-2.23}{1}{2.23}
\functionalline[\sin(x)]{sin(x*180/3.14)}{2}{3.14,6.28}
\functionalline[(x-\sqrt{5})\cdot \sin(x)]{(x-2.23)*sin(x*180/3.14)}{3}{2.23,3.14,6.28}
\end{functionallines}
\end{document}