If you define your function using \def\<function macro>(#1){\pgfmathparse{...#1...}
, you can use the function in all the applications you mentioned by saying \<function macro>(x)
or \<function macro>(x-1)
, or \<function macro>(2.4)
. This will work both when using Gnuplot and when using straight PGFplots:
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\def\FunctionF(#1){(#1)^3}%
\newcommand*{\SpecialXValue}{1.5}%
\begin{document}
\begin{tikzpicture}
\begin{axis}[
domain=-3:3, samples=50,
enlargelimits=false,
ymin=-5, ymax=5,
every axis plot post/.style= ultra thick]
\addplot [red] gnuplot {\FunctionF(x)};%
\addplot [blue] gnuplot {\FunctionF(x+1)};%
\addplot [cyan] {(x<1)*(3-3*x)+!(x<1)*-\FunctionF(x-1.5))};
\pgfmathsetmacro{\specialY}{\FunctionF(-1.5)}
\fill (axis cs:-1.5,\specialY) circle [radius=2pt] node [right] {(2,\specialY)};
\end{axis}
\end{tikzpicture}
\end{document}
Old Answer:
You can redefine the x
function to return a constant value (in your case \SpecialXValue
) before calculating the y
value. The easiest way to do that is to issue
\tikzset{declare function={x=\SpecialXValue;}}
just before you calculate the y
value.
You can still add new functions after this, the definition of x
as a fixed value doesn't persist.
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\newcommand*{\XAxisMin}{-1.0}
\newcommand*{\XAxisMax}{3.0}
\newcommand*{\YAxisMin}{-2.0}
\newcommand*{\YAxisMax}{10}
\newcommand*{\DomainMinF}{\XAxisMin}
\newcommand*{\DomainMaxF}{2.2}
\pgfkeys{/pgfplots/Axis Style/.style={
xmin=\XAxisMin, xmax=\XAxisMax,
ymin=\YAxisMin, ymax=\YAxisMax,
domain=\DomainMinF:\DomainMaxF,
width=6.5cm
}}
% Gnuplot options here have no effect if not using GnuPlot
\pgfkeys{/pgfplots/Plot Style/.style={
translate gnuplot=true,% can use ‘^’ instead of ‘**’
id=foo,
mark=none,%
domain=\DomainMinF:\DomainMaxF,%
samples=50,%
ultra thick,
}}
\newcommand*{\LabelPoint}[2]{\fill (axis cs:#1,#2) circle [radius=3pt] node [right] {\footnotesize$(#1,#2)$};}%
\newcommand*{\FunctionFGnuplot}{(x)^3}%
\newcommand*{\SpecialXValue}{1.1}%
\begin{document}
\begin{tikzpicture}
\begin{axis}[Axis Style]
\addplot [Plot Style, red] gnuplot {\FunctionFGnuplot};%
\tikzset{declare function={x=\SpecialXValue;}}
\pgfmathsetmacro{\YatSpecialX}{\FunctionFGnuplot}%
\LabelPoint{\SpecialXValue}{\YatSpecialX}
\end{axis}
\end{tikzpicture}
\end{document}
The scaled x ticks
key only acts after the tick positions have already been determined, so they're not the way to go here. Instead, you should transform your coordinate system using x coord trafo/.code
and y coord trafo/.code
.
Note that for values as large as yours, you'll need to switch on the fpu
library in the .code
. When using xmin
, xmax
, etc., the fpu
library needs to be deactivated after the calculation, but when plotting mathematical expressions, the library may not be deactivated. This is a bit cumbersome: You'll have to \pgflibraryfpuifactive
to decide whether we're in a context where the libary should be switched on and off, or left as it is:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0, xmax=70000,
ymin=0, ymax=5000,
domain=0:70000,
x coord trafo/.code={
\pgflibraryfpuifactive{
\pgfmathparse{(#1)/(19099)}
}{
\pgfkeys{/pgf/fpu=true}
\pgfmathparse{(#1)/(19099)}
\pgfkeys{/pgf/fpu=false}
}
},
y coord trafo/.code={
\pgflibraryfpuifactive{
\pgfmathparse{(#1)/(2000)}
}{
\pgfkeys{/pgf/fpu=true}
\pgfmathparse{(#1)/(2000)}
\pgfkeys{/pgf/fpu=false}
}
},
]
\addplot {2000+0.001*(x/60)^2};
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
What you're looking for is
axis y line=none
: