23

I have a pgf plot. Now the scale on the x-axis is at the moment frequency, hz, but it should be rad/s to save myself time exporting the file again is it possible to multiply the x-coordinate of every data point with a certain factor easily in pgf plots? In this case 2*pi?

WG-
  • 2,860

2 Answers2

27

use x expr as in

\addplot table[x expr=\thisrowno{0}*2*pi, y index=1] {\table};

assuming that your abscissas are stored in the first column of a table loaded in the macro \table and your ordinates in the second.

More details are given on page 29 of the pgfplots manual.

M. Toya
  • 3,227
10

Yes it is! From the pgfplots manual:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
    \begin{axis}[
    xtick={0,1.5708,...,10},
    domain=0:2*pi,
    scaled x ticks={real:3.1415},
    xtick scale label code/.code={$\cdot \pi$}]
    \addplot {sin(deg(x))};
    \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

The option of interest is the scaled x ticks={real:3.1415}, which tells pgfplots to scale the x values by a factor of 3.1415. You can switch off the "times PI" part below the axis by removing the xtick scale label code/.code={$\cdot \pi$} code.

Benedikt Bauer
  • 6,590
  • 2
  • 34
  • 60
  • 2
    the OP wants to multiply the domain by a certain factor (2\pi), not to change the tick labels appearance. See Alfred M. answer (or x filter key from the manual). – Luigi Oct 06 '12 at 14:17
  • But in the outcome, this should be the same, whether I scale the axis to show the "wrong" data points at the "right" x value or whether I multiply the values to get them to the right value, shouldn't it? – Benedikt Bauer Oct 06 '12 at 14:22
  • Yes you are correct Benedikt, but that is not what I wanted. But thanks for your answer aswell :) – WG- Oct 06 '12 at 14:26
  • 1
    As far as I can see, the real:<num> scales the axis by dividing all the axis points by ``´´. So if you want to end up with {2\pi}^2, you would have to scale the axis with 1/(2\pi)... – Benedikt Bauer Oct 06 '12 at 14:45
  • I think this answer should be more upvoted than the accepted answer because it is applicable to multiple \addplot within the same axis environment and also allows scaling if you have additional features (e.g. error bars). – honey_badger Feb 20 '20 at 15:04
  • This is a great answer. Unfortulately, I could not find an answer on how to remove the scale from the finished plot (The *PI it shows in the bottom right in this example). – Marv Jul 07 '20 at 18:48