Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Percent sign in sprintf string for gnuplot label

1,644 views
Skip to first unread message

Philipp

unread,
Nov 2, 2010, 6:18:22 AM11/2/10
to
Hi all,

I've come across the problem of including a percent sign in a sprintf
string in gnuplot. The figure I'm trying to create works great without
the percent sign in the label of each data point. Now, I'd like to add
the percent sign, but am failing miserably. I|ve been successful with
adding percent signs on xlabel and ylabel, but I can't get a hang of
the sprintf syntax.


I'm multiplying the value from colum two by some term and then want to
add the number on top of the entry in the chart.

The corresponding snippet:

sprintf("%2.2f \\%%",($2*0.001*0.25/(88*30)*100*0.07))) # doesn't work
sprintf("%2.2f",($2*0.001*0.25/(88*30)*100*0.07))) # works well, but
lacks the percent sign.

Here's the complete code, as it is found in my .tex file

\begin{gnuplottex}

plot file using (($1+1)/4-5):($2*0.001*0.25/(88*30)*0.07) every
4::start::32 with boxes fs solid,\
file using (($1+1)/4-5):(0.02 + $2*0.001*0.25/(88*30)*0.07):
(sprintf("%2.2f \\%%",($2*0.001*0.25/(88*30)*100*0.07))) every
4::start::32 with labels

\end{gnuplottex}


Any help would be much appreciated!

Christoph Bersch

unread,
Nov 2, 2010, 6:51:12 AM11/2/10
to
Am 02.11.2010 11:18, schrieb Philipp:
> Hi all,
>
> I've come across the problem of including a percent sign in a sprintf
> string in gnuplot. The figure I'm trying to create works great without
> the percent sign in the label of each data point. Now, I'd like to add
> the percent sign, but am failing miserably. I|ve been successful with
> adding percent signs on xlabel and ylabel, but I can't get a hang of
> the sprintf syntax.
>
>
> I'm multiplying the value from colum two by some term and then want to
> add the number on top of the entry in the chart.
>
> The corresponding snippet:
>
> sprintf("%2.2f \\%%",($2*0.001*0.25/(88*30)*100*0.07))) # doesn't work

typing

print sprintf("%2.2f %%", 1)

on the gnuplot command line correctly gives "1.00 %"

> Here's the complete code, as it is found in my .tex file

I guess this is not the complete code... At least this is not
compileable and it seems that this is a problem related to the LaTeX
processing (on the command line %% works).
Which package provides the gnuplottex environment?
>
> \begin{gnuplottex}
[...]

Christoph

Philipp

unread,
Nov 2, 2010, 6:57:17 AM11/2/10
to

Hi Christopf, thanks for your time. The gnuplot environement is
provided by the gnuplottex package. I mistakenly named the environemtn
'gnuplottex' instead of the correct 'gnuplot' in this post. It's
correct in the .tex file.

Concerning the sprintf command from the command line in gnuplot. I
have also verified that this works. So you suggest it's a problem with
the 'gnuplottex' package and sprintf?

Thanks again!

Christoph Bersch

unread,
Nov 2, 2010, 7:59:58 AM11/2/10
to
Am 02.11.2010 11:57, schrieb Philipp:
>
> The gnuplot environement is
> provided by the gnuplottex package. I mistakenly named the environemtn
> 'gnuplottex' instead of the correct 'gnuplot' in this post. It's
> correct in the .tex file.
>
> Concerning the sprintf command from the command line in gnuplot. I
> have also verified that this works. So you suggest it's a problem with
> the 'gnuplottex' package and sprintf?

No, it is a problem of escaping the % character correctly. This depends
on the terminal you use with gnuplottex. The following works for me:

\documentclass{article}
\usepackage{gnuplottex}

\begin{document}
\begin{gnuplot}[terminal=epslatex]
plot sin(x) t sprintf('%2.2f \%%', 1)
\end{gnuplot}

\begin{gnuplot}[terminal=postscript, terminaloptions=eps]
plot sin(x) t sprintf('%2.2f %%', 1)
\end{gnuplot}
\end{document}

Christoph

0 new messages