{"id":14462,"date":"2026-07-31T01:00:00","date_gmt":"2026-07-31T05:00:00","guid":{"rendered":"https:\/\/www.both.org\/?p=14462"},"modified":"2026-07-27T13:44:51","modified_gmt":"2026-07-27T17:44:51","slug":"using-libreoffice-to-chart-xy-data","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=14462","title":{"rendered":"Using LibreOffice to chart x,y data"},"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=\"14462\" 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\">When I was an undergraduate physics student in the early 1990s, we wrote a lot of FORTRAN 77 programs to analyze lab data or perform simulations. FORTRAN is an old programming language, but it makes easy work for anything that involves mathematics.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Unfortunately, FORTRAN 77 doesn\u2019t support any kind of graphics interface. You can\u2019t just draw a chart in graphics mode to see what your data looks like. Instead, you have to generate your data and use another program to display a chart from it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s one example to do that, using LibreOffice to chart x,y data generated from a FORTRAN 77 program.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Mandelbrot Set<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">One way to demonstrate x,y data is with complex numbers. Complex numbers are always a 2-value number: a <em>real<\/em> part and an <em>imaginary<\/em> part, usually written as <em>x<\/em>\u2005+\u2005<em>y<\/em><em>i<\/em> where <em>x<\/em> is the real part and <em>y<\/em> is the imaginary part. The value for <em>i<\/em> is actually \u201cthe square root of -1\u201d which isn\u2019t usually allowed\u2014unless you use complex numbers, then \u201cthe square root of -1\u201d is just the complex number 0\u2005+\u20051<em>i<\/em>. With both a real part and an imaginary part, you can think of a complex number as basically x,y data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <a href=\"https:\/\/en.wikipedia.org\/wiki\/Mandelbrot_set\">Mandelbrot Set<\/a> is a plot of the complex numbers in a certain range, using the function <em>z<\/em>\u2004=\u2004<em>z<\/em><sup>2<\/sup>\u2005+\u2005<em>c<\/em> where both <em>z<\/em> and <em>c<\/em> are complex numbers. To calculate the Mandelbrot set, you iterate through different values of <em>c<\/em>, and always use a starting value of <em>z<\/em>\u2004=\u20040. Each iteration uses the previous value of <em>z<\/em>, so you calculate one value of <em>z<\/em> as <em>z<\/em>\u2004=\u2004<em>z<\/em><sup>2<\/sup>\u2005+\u2005<em>c<\/em>, then use <em>that value of z<\/em> for the next iteration, as <em>z<\/em>\u2004=\u2004<em>z<\/em><sup>2<\/sup>\u2005+\u2005<em>c<\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Calculating the values in FORTRAN 77<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This is easy to calculate in FORTRAN 77, since FORTRAN has a <code>COMPLEX<\/code> data type. If we have two <code>REAL<\/code> variables <code>X<\/code> and <code>I<\/code>, we can combine these to create a <code>COMPLEX<\/code> value in FORTRAN, using the function <code>CMPLX(X,I)<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I won\u2019t go into the details of the FORTRAN 77 programming language here, except to note that every line is usually written in all-uppercase. Each line uses column rules: Columns 1 to 5 are for <em>line labels<\/em>, which look like line numbers but are really just references. A line with <code>C<\/code> or <code>*<\/code> in column 1 is ignored as a <em>comment line<\/em>. Column 6 indicates a <em>continuation<\/em> from the previous line. Columns 7 to 72 are for <em>program statements<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">FORTRAN supports several kinds of conditional statements. One is the <code>IF<\/code> statement, which you might recognize from other programming or scripting languages. Another is the <code>DO<\/code> statement, which is essentially a kind of loop that specifies the <em>starting value<\/em>, <em>ending value<\/em>, and <em>increment value<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With these basics, we can write a short FORTRAN 77 program that iterates between different values of <code>C<\/code>, from the starting complex number \u22122.5\u2005+\u20051<em>i<\/em> in the upper left to the ending value 1\u2005\u2212\u20051<em>i<\/em> in the lower right. At the start of each iteration, we set the initial value of <code>Z<\/code> to zero.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>      PROGRAM MDELBROT\n      PARAMETER(STEP=.05)\n      REAL DIST\n      REAL X,I\n      COMPLEX Z,C\n      INTEGER COUNT\n      DO 100 X=-2.5,1.0,STEP\n      DO 90  I=1.0,-1.0,-STEP\n      C = CMPLX(X,I)\n      Z = CMPLX(0.0, 0.0)\n      COUNT = 0\n10    Z = Z**2 + C\n      DIST=REAL(Z)**2 + IMAG(Z)**2\n      COUNT = COUNT + 1\n      IF ((DIST.LT.4.0) .AND. (COUNT.LT.100)) GOTO 10\nC PRINT IT SO IT WILL FIT IN A CSV AND WE CAN DO AN X,Y CHART\nC WITH IT IN LIBREOFFICE (ONLY PRINT IF COUNT.EQ.100)\n      IF (COUNT.EQ.100) PRINT 910, C\n910   FORMAT(F6.3,1H,,F6.3)\n90    CONTINUE\n100   CONTINUE\n      END<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Note that each value of <code>C<\/code> is iterated only so many times, otherwise it would take forever. For each <code>C<\/code>, we check two things: has the iteration gone on too long, or has the value of <code>Z<\/code> become too large (mathematically, this means it has \u201cescaped\u201d or \u201cexploded\u201d and can be ignored). After 100 iterations, if the value of <code>Z<\/code> is still small, we print a mark for the x,y value (the complex value <em>x<\/em>\u2005+\u2005<em>y<\/em><em>i<\/em>) then move on to test the next value of <code>C<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Save this source file as <code>mand.f<\/code>, then compile it using the GNU Fortran compiler, or with the <a href=\"https:\/\/www.both.org\/?p=14140\">f2c compiler<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ gfortran -std=legacy -o mand mand.f<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">or:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ f2c mand.f\n$ gcc -o mand mand.c -lm -lf2c<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Using either method will generate a program called <code>mand<\/code> that we can run to generate a set of x,y values that define the Mandelbrot Set. This program generates just over 600 x,y comma-separated values:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ .\/mand &gt; mand.csv\n\n$ wc -l mand.csv\n617 mand.csv\n\n$ head mand.csv\n-1.750,  .000\n-1.400,  .000\n-1.350,  .050\n-1.350,  .000\n-1.350, -.050\n-1.300,  .050\n-1.300,  .000\n-1.300, -.050\n-1.250,  .000\n-1.200,  .150<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Plot the data in LibreOffice<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To create an image of the Mandelbrot Set, we need to plot the data generated by the <code>mand<\/code> program. Since this is just x,y data, we can use a familiar spreadsheet like LibreOffice Calc to do it for us.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Start the LibreOffice Calc app, and use the <strong>File &gt; Open<\/strong> menu action to open the <code>mand.csv<\/code> data file. LibreOffice will recognize this as a \u201cCSV\u201d file, or <em>comma separated values<\/em> file, and prompt you with an \u201cImport\u201d dialog box:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"716\" height=\"791\" src=\"http:\/\/www.both.org\/wp-content\/uploads\/2026\/07\/calc-import.png\" alt=\"a dialog box showing options to import data into a spreadsheet: the data is in 2-column format\" class=\"wp-image-14460\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Everything looked okay to me, so I accepted the defaults. This loads the full data file into the spreadsheet, as two columns:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"950\" height=\"984\" src=\"http:\/\/www.both.org\/wp-content\/uploads\/2026\/07\/calc-data.png\" alt=\"a spreadsheet showing two columns of numbers\" class=\"wp-image-14459\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Use the <strong>Insert > Chart<\/strong> menu action to create a new chart using this data. Since the spreadsheet only has two columns in it, LibreOffice Calc should interpret the first column as the <em>x<\/em> data and the second column as the <em>y<\/em> data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To plot the Mandelbrot Set data, I only needed to change two defaults in the LibreOffice Chart. First, set the Chart Type to \u201cXY (Scatter)\u201d and use \u201cPoints Only.\u201d Then, turn off the legend and grids in Chart Elements.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"945\" height=\"484\" src=\"http:\/\/www.both.org\/wp-content\/uploads\/2026\/07\/calc-chart1.png\" alt=\"a dialog box showing options for a chart type; the type has been changed to show XY data as points\" class=\"wp-image-14457\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"945\" height=\"484\" src=\"http:\/\/www.both.org\/wp-content\/uploads\/2026\/07\/calc-chart2.png\" alt=\"a dialog box showing options for chart elements; the legend and grids are both left unmarked\" class=\"wp-image-14458\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">With those settings, LibreOffice Calc should generate a chart showing the Mandelbrot Set. Each point in the data set is displayed as a small dark-blue square, so the data is really just a low-resolution version of the Mandelbrot Set. But even in this \u201cblocky\u201d resolution, you can still see the familiar shape of the Mandelbrot Set.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"950\" height=\"984\" src=\"http:\/\/www.both.org\/wp-content\/uploads\/2026\/07\/calc-mandelbrot.png\" alt=\"a spreadsheet showing two columns of numbers and a blocky blue chart\" class=\"wp-image-14461\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Plotting data in LibreOffice Calc<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This demonstration is very similar to how I displayed data from programs, when I was an undergraduate student in the 1990s. And I think it\u2019s a fun exercise to see what new things you can do just by writing a short FORTRAN program, and using a few cool chart features in LibreOffice Calc.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spreadsheets aren\u2019t just for numbers, they also make great charts<\/p>\n","protected":false},"author":33,"featured_media":3302,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[237,5,150],"tags":[133,152],"class_list":["post-14462","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-libreoffice","category-linux","category-programming","tag-libreoffice","tag-programming"],"modified_by":"Jim Hall","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14462","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14462"}],"version-history":[{"count":2,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14462\/revisions"}],"predecessor-version":[{"id":14464,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14462\/revisions\/14464"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/3302"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}