{"id":14522,"date":"2026-08-14T01:00:00","date_gmt":"2026-08-14T05:00:00","guid":{"rendered":"https:\/\/www.both.org\/?p=14522"},"modified":"2026-08-04T18:40:16","modified_gmt":"2026-08-04T22:40:16","slug":"charting-data-with-gnuplot","status":"publish","type":"post","link":"http:\/\/www.both.org\/?p=14522","title":{"rendered":"Charting data with gnuplot"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"14522\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><\/div>\n<p class=\"wp-block-paragraph\">I\u2019m working on a hobby book project that will include a&nbsp;<em>lot<\/em>&nbsp;of charts. And I really mean it\u2014there are a ton of charts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I want to make sure that my charts and graphs all look the same. With that many graphs, doing it in a spreadsheet application like LibreOffice isn\u2019t very appealing. That\u2019s okay for a few charts, but after a dozen or more charts, I know making each chart&nbsp;<em>look the same<\/em>&nbsp;will become tedious, especially if I decide halfway through the project that it would be better if all of the charts used a&nbsp;<em>slightly<\/em>&nbsp;different style. Updating every chart&nbsp;<em>by hand<\/em>&nbsp;will be impossible.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So I\u2019m going back to a plotting system that I used in the 1990s when I was an undergraduate physics student:&nbsp;<a href=\"http:\/\/gnuplot.info\/\">gnuplot<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is gnuplot<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Despite the name, gnuplot is&nbsp;<a href=\"http:\/\/www.gnuplot.info\/faq\/index.html#x1-70001.2\">not part of the GNU project<\/a>&nbsp;and has nothing to do with the Free Software Foundation. It was developed independently; the name is a compromise among the developers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">gnuplot (the name is properly spelled&nbsp;<em>all lowercase<\/em>) specializes in visualizing data. I used it in my undergrad years to make plots of my physics lab data or to show the results of equations, but gnuplot&nbsp;<a href=\"http:\/\/www.gnuplot.info\/faq\/index.html#x1-80001.3\">supports other chart types<\/a>&nbsp;including:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Two-dimensional functions and data plots combining many different elements such as points, lines, error bars, filled shapes, labels, arrows, \u2026<\/li>\n\n\n\n<li>Polar axes, log-scaled axes, general nonlinear axis mapping, parametric coordinates<\/li>\n\n\n\n<li>Data representations such as heat maps, beeswarm plots, violin plots, histograms, \u2026<\/li>\n\n\n\n<li>Three-dimensional plots of data points, lines, and surfaces in many different styles (contour plot, mesh)<\/li>\n\n\n\n<li>Algebraic computation using integer, floating point, or complex arithmetic<\/li>\n\n\n\n<li>Data-driven model fitting using Marquardt-Levenberg minimization<\/li>\n\n\n\n<li>Support for a large number of operating systems, graphics file formats and output devices<\/li>\n\n\n\n<li>Extensive on-line help<\/li>\n\n\n\n<li>TeX-like text formatting for labels, titles, axes, data points<\/li>\n\n\n\n<li>Interactive command line editing and history<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">You can also generate all kinds of output, including PDF (which you can include in a LaTeX document) or a PNG image (which is useful in lots of places). These output types are defined as&nbsp;<em>terminals<\/em>; by default, gnuplot uses a graphical \u201cterminal\u201d output so you can see the results as you go.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A few samples<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">First, run&nbsp;<code>gnuplot<\/code>&nbsp;from the command line, which will start the program in&nbsp;<em>interactive<\/em>&nbsp;mode with a&nbsp;<code>gnuplot&gt;<\/code>&nbsp;prompt:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ gnuplot\n\n    G N U P L O T\n    Version 6.0.3 patchlevel 3    last modified 2025-06-01 \n\n    Copyright (C) 1986-1993, 1998, 2004, 2007-2025\n    Thomas Williams, Colin Kelley and many others\n\n    gnuplot home:     http:\/\/www.gnuplot.info\n    faq, bugs, etc:   type \"help FAQ\"\n    immediate help:   type \"help\"  (plot window: hit 'h')\n\n    Terminal type is now qt\ngnuplot&gt; <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s start by plotting the sine curve. To do that, enter this instruction:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; plot sin(x)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"642\" height=\"546\" src=\"http:\/\/www.both.org\/wp-content\/uploads\/2026\/08\/gnuplot-sine.png\" alt=\"a repeat of the sine curve from -10 to 10\" class=\"wp-image-14519\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">If you move your mouse over the chart, gnuplot will show the&nbsp;<em>x,y<\/em>&nbsp;coordinates in the lower-left of the screen. The \u201c3.06243, 1.03757\u201d numbers show the coordinates where I happened to move my mouse when I took the screenshot; you can ignore these numbers in my screenshots.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Without parameters, gnuplot assumes some defaults for the chart. It tries to adjust the&nbsp;<em>y<\/em>&nbsp;axis to show all of the values, which is why the&nbsp;<em>y<\/em>&nbsp;axis goes from -1 to 1. I didn\u2019t provide an&nbsp;<em>x<\/em>&nbsp;axis range, so gnuplot charted the values from -10 to 10.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Adjust the range for the axes using square brackets. The first set of brackets defines the&nbsp;<em>x<\/em>&nbsp;range, providing a second set of brackets also specifies the&nbsp;<em>y<\/em>&nbsp;range. Let\u2019s display the sine curve from 0 to pi, like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; plot &#91;0:pi] sin(x)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"642\" height=\"546\" src=\"http:\/\/www.both.org\/wp-content\/uploads\/2026\/08\/gnuplot-sine-pi.png\" alt=\"part of the sine curve from 0 to pi\" class=\"wp-image-14521\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">That only shows half of the sine curve, so let\u2019s adjust this to 2 pi instead:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; plot &#91;0:2*pi] sin(x)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"642\" height=\"546\" src=\"http:\/\/www.both.org\/wp-content\/uploads\/2026\/08\/gnuplot-sine-2pi.png\" alt=\"the sine curve from 0 to 2 pi\" class=\"wp-image-14520\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A common chart that I will need to produce is a line graph, using&nbsp;<em>x,y<\/em>&nbsp;data. Let\u2019s look at an example. I created some simple linear data, and saved it to a file. Each&nbsp;<em>x<\/em>&nbsp;and&nbsp;<em>y<\/em>&nbsp;value is separated by a space, each&nbsp;<em>x,y<\/em>&nbsp;pair is on a new line.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1.21 2.1\n1.22 2.2\n1.23 2.3\n1.24 2.4\n1.25 2.5\n1.26 2.6\n1.27 2.7\n1.28 2.8\n1.29 2.9<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Save this file as&nbsp;<code>line.dat<\/code>, and use gnuplot to chart it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; plot 'line.dat'<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This generates a simple&nbsp;<em>x,y<\/em>&nbsp;chart that shows each data pair as a point on the chart. It looks very line-shaped, because that\u2019s how I created the data:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"642\" height=\"546\" src=\"http:\/\/www.both.org\/wp-content\/uploads\/2026\/08\/gnuplot-line.png\" alt=\"a set of points that increase from the lower left to the upper right\" class=\"wp-image-14515\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">My typical use case will require showing both data points&nbsp;<em>and<\/em>&nbsp;lines. To do that, change the chart style using the&nbsp;<code>with linespoints<\/code>&nbsp;phrase:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; plot 'line.dat' with linespoints<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"642\" height=\"546\" src=\"http:\/\/www.both.org\/wp-content\/uploads\/2026\/08\/gnuplot-linespoints.png\" alt=\"a line chart that increases from the lower left to the upper right\" class=\"wp-image-14517\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">But in this case, I don\u2019t like how the data is displayed, with the&nbsp;<em>x<\/em>&nbsp;axis from 1.21 to 1.29, and the&nbsp;<em>y<\/em>&nbsp;axis from 2.1 to 2.9 (the data starts at 1.21,2.1 and ends at 1.29,2.9). Let\u2019s change the&nbsp;<em>x<\/em>&nbsp;axis from 1.2 to 1.3, and the&nbsp;<em>y<\/em>&nbsp;from 2 to 3 using a pair of square brackets:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; plot &#91;1.2:1.3] &#91;2:3] 'line.dat' with linespoints<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"642\" height=\"546\" src=\"http:\/\/www.both.org\/wp-content\/uploads\/2026\/08\/gnuplot-linespoints2.png\" alt=\"a line chart that increases from the lower left to the upper right\" class=\"wp-image-14518\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">For my project, I\u2019ll need to save the output in a format that can be used in a LaTeX document. One way to do this is to save the chart as a PDF file, and include it in a LaTeX document with&nbsp;<code>\\usepackage{graphicx}<\/code>&nbsp;and&nbsp;<code>\\includegraphics{chart}<\/code>. If you process the LaTeX document using the&nbsp;<code>latex<\/code>&nbsp;command,&nbsp;<code>\\includegraphics{chart}<\/code>&nbsp;will look for&nbsp;<code>chart.ps<\/code>. If you use the&nbsp;<code>pdflatex<\/code>&nbsp;command to generate PDF output,&nbsp;<code>\\includegraphics{chart}<\/code>&nbsp;will look for&nbsp;<code>chart.pdf<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s save this chart so it can be included in a LaTeX document. To do that, you need to change the \u201cterminal\u201d type to&nbsp;<code>pdf<\/code>. Then, set the output to a new file and regenerate the chart:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gnuplot&gt; set terminal pdf\n\nTerminal type is now 'pdfcairo'\nOptions are ' transparent enhanced fontscale 0.5 size 5.00in, 3.00in '\ngnuplot&gt; set output \"line.pdf\"\ngnuplot&gt; plot &#91;1.2:1.3] &#91;2:3] 'line.dat' with linespoints<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I can\u2019t include a PDF chart in this article, so let me change the \u201cterminal\u201d type to&nbsp;<code>png<\/code>&nbsp;and regenerate the chart with a new name:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gnuplot&gt; set terminal png\n\nTerminal type is now 'png'\nOptions are 'truecolor nocrop enhanced butt size 640,480 font \"\/usr\/share\/fonts\/dejavu\/DejaVuSans.ttf,12.0\" '\ngnuplot&gt; set output \"gnuplot-line-chart.png\"\ngnuplot&gt; plot &#91;1.2:1.3] &#91;2:3] 'line.dat' with linespoints<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"480\" src=\"http:\/\/www.both.org\/wp-content\/uploads\/2026\/08\/gnuplot-line-chart.png\" alt=\"a line chart that increases from the lower left to the upper right\" class=\"wp-image-14516\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">You don\u2019t have to generate all of the charts in \u201cinteractive\u201d mode. gnuplot also supports reading commands from a file; this makes it much easier to keep all charts looking the same. For example, to regenerate the same chart&nbsp;<em>the same way<\/em>&nbsp;every time, I could save these commands in a file called&nbsp;<code>line.gnuplot<\/code>&nbsp;(the extension doesn\u2019t matter)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>set terminal png\nset output \"gnuplot-line-chart.png\"\nplot &#91;1.2:1.3] &#91;2:3] 'line.dat' with linespoints<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To generate the chart again, run&nbsp;<code>gnuplot<\/code>&nbsp;with this file as an option:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ gnuplot line.gnuplot<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I\u2019m looking forward to using this feature to generate all of my charts using similar options, so they all look the same.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">gnuplot supports a ton of options and can display all kinds of charts and graphs, including box plots, surface plots, histograms, Gantt charts, vector, splines, scatter plots, and other kinds of charts. You can see&nbsp;<a href=\"http:\/\/gnuplot.info\/screenshots\/index.html#demos\">demos of different chart styles<\/a>&nbsp;on the gnuplot website. To learn how to use gnuplot, start with the&nbsp;<a href=\"http:\/\/gnuplot.info\/help.html\">online tutorials<\/a>&nbsp;and other resources, also available on the gnuplot website.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This venerable chart tool supports a load of options.<\/p>\n","protected":false},"author":33,"featured_media":3545,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[100,178],"tags":[104,207],"class_list":["post-14522","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-command-line","category-tools","tag-command-line","tag-tools"],"modified_by":"Jim Hall","_links":{"self":[{"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14522","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"http:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14522"}],"version-history":[{"count":2,"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14522\/revisions"}],"predecessor-version":[{"id":14533,"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14522\/revisions\/14533"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/3545"}],"wp:attachment":[{"href":"http:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14522"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}