{"id":1702,"date":"2020-06-25T22:04:32","date_gmt":"2020-06-25T14:04:32","guid":{"rendered":"https:\/\/people.utm.my\/yap\/?page_id=1702"},"modified":"2020-06-25T23:25:39","modified_gmt":"2020-06-25T15:25:39","slug":"plotting-function-in-gnuplot","status":"publish","type":"page","link":"https:\/\/people.utm.my\/yap\/plotting-function-in-gnuplot\/","title":{"rendered":"Plotting Function in Gnuplot"},"content":{"rendered":"<p style=\"text-align: right\"><span style=\"font-size: 12pt\">(<a href=\"https:\/\/people.utm.my\/yap\/plotting-and-fitting-using-gnuplot\/\">Back to index page<\/a>)<\/span><\/p>\n<p>For starters, let&#8217;s try to plot functions (without data) in Gnuplot.<\/p>\n<p><span style=\"font-size: 12pt\">In a graph, you have the x and y axis.<\/span><\/p>\n<p><span style=\"font-size: 12pt\">For Gnuplot, the y-axis is not called &#8220;y&#8221;&#8230; instead, you use a function to define it..<\/span><\/p>\n<p><span style=\"font-size: 12pt\">e.g. y = mx + c<\/span><\/p>\n<p><span style=\"font-size: 12pt\"><strong>For gnuplot, you will need to write it this way (write this in your script):\u00a0<\/strong><\/span><\/p>\n<p><span style=\"font-size: 12pt\"><span style=\"color: #0000ff\"><em>#\u00a0 sets the number of points in the entire graph<br \/>\n<\/em>set samples 10<\/span><\/span><\/p>\n<p><span style=\"font-size: 12pt\"><span style=\"color: #0000ff\"><em>#\u00a0 this is the function<\/em><\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">f(x) = m*x + c<\/span><\/span><\/span><\/p>\n<p><span style=\"font-size: 12pt\"><span style=\"color: #0000ff\"><em># define the variables that you use<\/em><\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">m = 12<\/span><\/span><\/span><\/p>\n<p><span style=\"font-size: 12pt\"><span style=\"color: #0000ff\"><em># define the variables that you use<\/em><\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">c = 1<\/span><\/span><\/span><\/p>\n<p><span style=\"font-size: 12pt\"><span style=\"color: #0000ff\"><em># this plots the f(x) function with line<\/em><\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">plot f(x) with line<\/span><\/span><\/span><\/p>\n<p><span style=\"font-size: 12pt\"><span style=\"color: #0000ff\"><em># replot f(x) function with points<\/em><\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">replot f(x) with points pointtype 5<\/span><\/span><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size: 12pt\">Sometimes, you will need to set the y-axis and x-axis range.\u00a0 You can use this command.<\/span><\/p>\n<p><span style=\"font-size: 12pt\"><span style=\"color: #0000ff\"><em># this sets the y-axis range from 0 to 10<\/em><\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">set xrange [0:5]<\/span><\/span><\/span><\/p>\n<p><span style=\"font-size: 12pt\"><span style=\"color: #0000ff\"><em># this sets the x-axis range from (all) to 1.5<\/em><\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">set yrange [0:60]<\/span><\/span><\/span><\/p>\n<p><span style=\"font-size: 12pt\">Remember that the commands are sequential.\u00a0 So that means, it must appear <em><strong>before<\/strong> <\/em>the plotting command.<\/span><\/p>\n<p><span style=\"font-size: 12pt\">If you change the range <strong><em>after<\/em> <\/strong>plotting, it will not work.<\/span><\/p>\n<p><span style=\"font-size: 12pt\">If it is placed after, then you can replot existing plots using this command:<\/span><\/p>\n<p><span style=\"font-size: 12pt\"><span style=\"color: #0000ff\"># this will replot everything plotted previously.<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">replot<\/span><\/span><\/span><\/p>\n<p><a href=\"https:\/\/people.utm.my\/yap\/wp-content\/uploads\/sites\/1596\/2020\/06\/linear.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-1735\" src=\"https:\/\/people.utm.my\/yap\/wp-content\/uploads\/sites\/1596\/2020\/06\/linear.png\" alt=\"\" width=\"502\" height=\"266\" srcset=\"https:\/\/people.utm.my\/yap\/wp-content\/uploads\/sites\/1596\/2020\/06\/linear.png 1137w, https:\/\/people.utm.my\/yap\/wp-content\/uploads\/sites\/1596\/2020\/06\/linear-300x159.png 300w, https:\/\/people.utm.my\/yap\/wp-content\/uploads\/sites\/1596\/2020\/06\/linear-1024x542.png 1024w, https:\/\/people.utm.my\/yap\/wp-content\/uploads\/sites\/1596\/2020\/06\/linear-768x407.png 768w\" sizes=\"(max-width: 502px) 100vw, 502px\" \/><\/a><\/p>\n<hr \/>\n<p><span style=\"font-size: 12pt\">Let&#8217;s try a more complicated equation:<\/span><\/p>\n<h2>Gaussian Distribution Plot<\/h2>\n<p><span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">set samples 1000<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">g(x) = a*exp((-(x-b)**2)\/(2*c**2)) + d<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">a = 2<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">b = 3<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">c = 1.5<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">d = 0.2<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">set xrange [-10:10]<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">set yrange [0:3]<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">plot g(x) with linespoints<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<p><a href=\"https:\/\/people.utm.my\/yap\/wp-content\/uploads\/sites\/1596\/2020\/06\/Gaussian2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1733\" src=\"https:\/\/people.utm.my\/yap\/wp-content\/uploads\/sites\/1596\/2020\/06\/Gaussian2.png\" alt=\"\" width=\"498\" height=\"263\" srcset=\"https:\/\/people.utm.my\/yap\/wp-content\/uploads\/sites\/1596\/2020\/06\/Gaussian2.png 1137w, https:\/\/people.utm.my\/yap\/wp-content\/uploads\/sites\/1596\/2020\/06\/Gaussian2-300x159.png 300w, https:\/\/people.utm.my\/yap\/wp-content\/uploads\/sites\/1596\/2020\/06\/Gaussian2-1024x541.png 1024w, https:\/\/people.utm.my\/yap\/wp-content\/uploads\/sites\/1596\/2020\/06\/Gaussian2-768x406.png 768w\" sizes=\"(max-width: 498px) 100vw, 498px\" \/><\/a><\/p>\n<h2>A multifrequency, decaying sinosoidal plot<\/h2>\n<p><span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">set samples 1000<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">h(x) = exp(-x\/t1)*A1*sin(2*pi*f1*x+phi1) + exp(-x\/t2)*A2*sin(2*pi*f2*x+phi2) &#8211; d<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">A1 = 1<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">A2 = 2<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">phi1 = 0.5<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">phi2 = 0.3<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">t1 = 4<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">t2 = 2<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">f1 = 2<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">f2 = 10<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">d = 3<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">set xrange [0 : 10]<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">set yrange [-8:1]<\/span><br \/>\n<span style=\"font-size: 12pt\"><span style=\"color: #0000ff\">plot h(x) with line<\/span><br \/>\n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<p style=\"text-align: right\"><span style=\"font-size: 12pt\"><a href=\"https:\/\/people.utm.my\/yap\/wp-content\/uploads\/sites\/1596\/2020\/06\/Gaussian.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1731 aligncenter\" src=\"https:\/\/people.utm.my\/yap\/wp-content\/uploads\/sites\/1596\/2020\/06\/Gaussian.png\" alt=\"\" width=\"535\" height=\"281\" srcset=\"https:\/\/people.utm.my\/yap\/wp-content\/uploads\/sites\/1596\/2020\/06\/Gaussian.png 1136w, https:\/\/people.utm.my\/yap\/wp-content\/uploads\/sites\/1596\/2020\/06\/Gaussian-300x158.png 300w, https:\/\/people.utm.my\/yap\/wp-content\/uploads\/sites\/1596\/2020\/06\/Gaussian-1024x538.png 1024w, https:\/\/people.utm.my\/yap\/wp-content\/uploads\/sites\/1596\/2020\/06\/Gaussian-768x404.png 768w\" sizes=\"(max-width: 535px) 100vw, 535px\" \/><\/a><\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: right\"><span style=\"font-size: 12pt\">(<a href=\"https:\/\/people.utm.my\/yap\/plotting-and-fitting-using-gnuplot\/\">Back to index page<\/a>)<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>(Back to index page) For starters, let&#8217;s try to plot functions (without data) in Gnuplot. In a graph, you have the x and y axis. For Gnuplot, the y-axis is not called &#8220;y&#8221;&#8230; instead, you use a function to define it.. e.g. y = mx + c For gnuplot, you will need to write it [&hellip;]<\/p>\n","protected":false},"author":14205,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"class_list":["post-1702","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/people.utm.my\/yap\/wp-json\/wp\/v2\/pages\/1702","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/people.utm.my\/yap\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/people.utm.my\/yap\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/people.utm.my\/yap\/wp-json\/wp\/v2\/users\/14205"}],"replies":[{"embeddable":true,"href":"https:\/\/people.utm.my\/yap\/wp-json\/wp\/v2\/comments?post=1702"}],"version-history":[{"count":11,"href":"https:\/\/people.utm.my\/yap\/wp-json\/wp\/v2\/pages\/1702\/revisions"}],"predecessor-version":[{"id":1736,"href":"https:\/\/people.utm.my\/yap\/wp-json\/wp\/v2\/pages\/1702\/revisions\/1736"}],"wp:attachment":[{"href":"https:\/\/people.utm.my\/yap\/wp-json\/wp\/v2\/media?parent=1702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}