## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ Smooth Plot of Data Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
mas
Posts: 223
Joined: Thu Dec 04, 2008 4:39 am

### Smooth Plot of Data

I am trying to use pgfplots. Using Gnuplot, I can get a smooth curve as shown in figure below:

hipass-gp2.png (14.06 KiB) Viewed 12276 times

Wanted to get a similar output with pgfplot. My code is
\documentclass{standalone}%\usepackage{tikz}\usetikzlibrary{arrows}\usetikzlibrary{calc,through,backgrounds}\usepackage{pgfplots}\pgfplotsset{compat=1.8}%\usetikzlibrary{pgfplots.patchplots} \begin{document} \begin{tikzpicture}\begin{semilogxaxis}[xlabel=Frequency (Hz), ylabel=Gain]\addplot[no marks, smooth] coordinates {     (100 , 0.05)     (200 , 0.12)     (300 , 0.22)     (400 , 0.32)     (500 , 0.44)     (700 , 0.7)     (900 , 0.8)     (1000, 0.85)     (1500, 0.9)     (2000, 0.95)     (2500, 0.95)     (3000, 0.95)     (3500, 0.95)   } ;\addplot[only marks,red!50!black] coordinates {     (100 , 0.05)     (200 , 0.12)     (300 , 0.22)     (400 , 0.32)     (500 , 0.44)     (700 , 0.7)     (900 , 0.8)     (1000, 0.85)     (1500, 0.9)     (2000, 0.95)     (2500, 0.95)     (3000, 0.95)     (3500, 0.95)   } ;\end{semilogxaxis}\end{tikzpicture} \end{document}

I get a graph like

hipass-pgf2.png (17.34 KiB) Viewed 12276 times

What options should I give to get a plot similar to what I get from Gnuplot?

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim

Tags:

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
The green curve in the Gnuplot output seems to be the result of a fit operation, perhaps a sin²(a·x). Please post the corresponding Gnuplot script. But you could also read about the raw gnuplot key in the pgfplots manual to learn how to work with Gnuplot scripts inside pgfplots. A similar example has already been dicussed here some time ago [1]. Perhaps that can help you on.

[1] pgfplots | Logarithmic Trend line

Thorsten
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

mas
Posts: 223
Joined: Thu Dec 04, 2008 4:39 am
localghost wrote:The green curve in the Gnuplot output seems to be the result of a fit operation, perhaps a sin²(a·x). Please post the corresponding Gnuplot script.

The Gnuplot script I used is this one.
unset keyset logscale xset xrange [90:4e3]set yrange [0:1.1]set xlabel "Frequency (Hz)"set ylabel "Gain"set title "Frequency Response of a High Pass Filter"set terminal png set output "hipass.png"plot "hipass.dat" using ($1):($2/0.95) with points, \      "hipass.dat" using ($1):($2/0.95) smooth sbezier

But you could also read about the raw gnuplot key ...

Will do that and see if it helps.

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim

mas
Posts: 223
Joined: Thu Dec 04, 2008 4:39 am
localghost wrote:A similar example has already been dicussed here some time ago [1]. Perhaps that can help you on.

[1] pgfplots | Logarithmic Trend line

Took a look at that. As you can see from the gnuplot script, it is a bezier curve. Hence, there is no single function for the entire range.

Alternately, I looked at the patchplots of pgfplots. That also did not come out as I expected. My understanding about that is still very fuzzy. The output was not what I expected

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
As I already presumed the raw gnuplot key is one key to solve the problem. The other one is y expr to manipulate values in the y column. Your code then will look like this. The output is attached.
\documentclass[11pt]{standalone}\usepackage[T1]{fontenc}\usepackage{pgfplots}\pgfplotsset{   compat=newest,   xlabel near ticks,   ylabel near ticks} \usepackage{filecontents}\begin{filecontents*}{hipass.dat}x y100 0.05200 0.12300 0.22400 0.32500 0.44700 0.7900 0.81000 0.851500 0.92000 0.952500 0.953000 0.953500 0.95\end{filecontents*} \begin{document}   \begin{tikzpicture}     \begin{semilogxaxis}[       xlabel={Frequency (Hz)},       ylabel={Gain}     ]       \addplot[only marks,red!50!black] table[y expr=\thisrow{y}/0.95] {hipass.dat};       \addplot[raw gnuplot,smooth] gnuplot {         plot "hipass.dat" using ($1):($2/0.95) smooth sbezier       };     \end{semilogxaxis}   \end{tikzpicture}\end{document}

Remarks:

• The filecontents package and the corresponding filecontents* environment are only used here to generate the data file, thus not necessary in the actual document.
Attachments
ztmp.png (5.77 KiB) Viewed 12257 times
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

mas
Posts: 223
Joined: Thu Dec 04, 2008 4:39 am
Thanks. That is a nice solution.

Regards.

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim