I like that I can place a node at the end of plot and the node appears relative to the last point on the graph. When the domain is specified in increasing order \DomainMin:\DomainMax
, the label gets placed exactly where I want it -- both with, and without gnuplot
(see Graphs 1 and 2):
However, when the domain is specified in decreasing order DomainMax:\DomainMin
, I get the label where I want it if I use PGF to compute the coordinates (See Graph 3), but it is in the wrong place when I use gnuplot
(See Graph 4). I suspect this is because gnuplot
ignores the order the start and end of the domain are specified and computes coordinates in increasing x order.
I tried to use pos=0
thinking that it would place the label at the point I want, but this not quite the case -- it appears quite a bit lower, but don't know why.
So, is there a way I can use gnuplots
place the label the same place that pgfplots
places it when I specify the domain in decreasing order?
Here is the code that produces the above 5 graphs:
\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}
\newcommand*{\PlotLabel}{$y=x^3$}%
\pgfkeys{/pgfplots/Axis Style/.style={
clip=false,% so that we can see labels placed outside
xmin=\XAxisMin, xmax=\XAxisMax,
ymin=\YAxisMin, ymax=\YAxisMax,
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*{\AddLabel}[1]{\node [align = center] at (axis cs: 0.4,5) {#1};}%
\begin{document}
With increasing domain=$\DomainMinF:\DomainMaxF$, we get label at the end of the graph as desired:
\begin{tikzpicture}
\begin{axis}[Axis Style]
\addplot [Plot Style, blue, domain=\DomainMinF:\DomainMaxF]
{(x)^3} node [right] {\PlotLabel};%
\AddLabel{1. without \\ Gnuplot}
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[Axis Style]
\addplot [Plot Style, red, domain=\DomainMinF:\DomainMaxF]
gnuplot% Use Gnuplot for Graph 2
{(x)^3} node [right] {\PlotLabel};%
\AddLabel{2. with \\ Gnuplot}
\end{axis}
\end{tikzpicture}
\bigskip
But, with decreasing domain=$\DomainMaxF:\DomainMinF$, we get the label in the wrong spot with Gnuplot:
\begin{tikzpicture}
\begin{axis}[Axis Style]
\addplot [Plot Style, blue, domain=\DomainMaxF:\DomainMinF]
{(x)^3} node [right] {\PlotLabel};%
\AddLabel{3. without \\ Gnuplot}
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[Axis Style]
\addplot [Plot Style, red, domain=\DomainMaxF:\DomainMinF]
gnuplot% Use Gnuplot for Graph 4
{(x)^3} node [right] {\PlotLabel};% adding pos=0.0 does not work
\AddLabel{4. with \\ Gnuplot}
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[Axis Style]
\addplot [Plot Style, red, domain=\DomainMaxF:\DomainMinF]
gnuplot% Use Gnuplot for Graph 5
{(x)^3} node [right, pos=0.0] {\PlotLabel};
\AddLabel{5. with \\ Gnuplot (pos=0.0)}
\end{axis}
\end{tikzpicture}
\end{document}
pos
.linelabel
to work. I can try to recreate it and post as a separate question if you like. But, I normally either label at either end of the plot, or manually place the label independent of the plot.