gnuplot_test


gnuplot_test, a Python code which call gnuplot(), which reads, converts, and displays graphics information.

Ordinarily, the code is used interactively; that is, the user invokes the program, and then describes the plot to be created. The data for the plot is created either by a formula, or by reference to some data file created earlier.

It is often extremely important to be able to create graphical images of the results of an executable program. If the user is familiar with GNUPLOT, then the program can be modified to create a suitable data file, and, once the program has completed, the user can run GNUPLOT and use that data file to create a graph.

However, if the program is going to create the data file, it can just as easily create a file containing the appropriate commands to GNUPLOT that will create the desired image. In this way, the user can avoid having to recall the correct commands in the correct order to create the plot.

Thus, the program might create two files, called, perhaps data.txt and commands.txt. The command file would contain GNUPLOT commands, including one that refers to the data file itself. To create the graphics image, the user would simply type

        gnuplot < commands.txt
      

This directory includes some sample programs which carry out numerical calculations, creating data and command files that are used in exactly this way.

Some common plot types include:

Licensing:

The information on this web page is distributed under the MIT license.

Languages:

gnuplot_test is available in a non-language specific version and a C version and a C++ version and a Fortran77 version and a Fortran90 version and a MATLAB version and an Octave version and a Python version.

Related Data and Programs:

Reference:

  1. Philipp Janert,
    Gnuplot in Action: Understanding Data with Graphs,
    Manning, 2010,
    ISBN13: 978-1-933988-39-8,
    LC: QA276.4.J37.
  2. Thomas Williams, Colin Kelley,
    gnuplot 4.4, An Interactive Plotting Program,
    The Free Software Foundation, 2010.
  3. The GNUPLOT Website.

Source Code:

album_bar lists the year, and total number of music albums (LP's, cassettes, CD's and downloads) sold each year from 2007 to 2017. This data is plotted as a bar graph.

automobile_scatter contains prices and weights of cars available in 1985. A scatter plot is to be made.

brownian_2d_plot plots data representing 1000 steps of Brownian motion in two dimensions. Unlike a typical y=f(x) plot, this data wanders around the page.

bulgaria_plot takes data about the Bulgarian population over time and makes a plot of (time,population).

caffeine_scatter seeks a relationship between the percentage of blindness due to cataracts, and the daily intake of caffeine, in a number of countries. A scatter plot is produced.

corkscrew_plot3d generates (X,Y,Z) points that lie along a 3D curve looking something like a corkscrew.

correlation_heat_map takes an 8x8 correlation matrix and draws an 8x8 grid of squares, colored white for the highest values, yellow, then red, and black for the lowest.

corvette_scatter considers the resale price for Corvettes by model year, displaying the results as a scatter plot.

damped_sine evaluates the damped sine correlation function for a range of values of its argument. A plot of the function is desired.

drug_dosage_plots depicts measurements over 48 hours of the blood level concentration of a medicinal drug. The drug needs to reach a certain level to have an effect, but must not exceed the toxic level. A graphic is created which shows, on one plot, the concentration over time, the minimal effective level, and the maximum nonlethal leval.

faithful_histogram contains the waiting time in minutes between successive eruptions of the Old Faithful geyser.

geyser_scatter looks for relations between the duration in minutes of the eruption and following waiting times for the Old Faithful geyser.

grid_surface records, on a 41x41 grid over [-2,2]x[-2,+2], the values z = exp(-(x^2+y^2)) * cos(0.25*x) * sin(y) * cos(2*(x^2+y^2)). The data is plotted as a surface.

humps_plot plots the function y=humps(x) over [0,2]. Instead of a file of data, gnuplot() works directly with a formula for the function.

insect_scatter3d involves 3 data sets, each containing 10 measurements of 3 quantities for each of 3 species of insect. The quantities are first tarsus width, second tarsus width, and maximum width of the aedeagus. It is of interest to know whether these three measurements are enough to differentiate between members of the three species. A 3D scatter plot is created.

least_squares_plots compares 15 pairs of (x,y) data, the least squares line that approximates their behavior, and a quadratic curve that is much closer to the data.

mario_fill makes a simple image of Mario, by constructing a grid of squares filled with color. Instead of a data file, gnuplot() is given a list of squares and the appropriate colors to assign them.

mark_points adds green and red dots to mark the first and last data points in a plot.

nile_histogram makes a histogram of the yearly measurement of the height of the Nile at maximum flood. By lumping the data into bins, it is easier to see the range of flood heights, and the probability of various values in the range.

orbital_fill makes a color contour plot of orbital data.

predator_plot3d models the populations of predators (foxes) and prey (rabbits) over time. A 3D plot of (time, rabbits, foxes) is created.

president_heights_bar plots the heights of US presidents in inches, as a bar plot.

price_plots reads a table of average monthly prices for 11 consumer products, between February 2008 and February 2018, as compiled by the Bureau of Labor Statistics, and plots together the prices of three of the items.

snowfall_plot makes a line plot of the snowfall at Michigan Tech from 1890 to 2017.

string_simulation simulates the behavior of a string that obeys the wave equation. The shape of the string is to be plotted over successive times.

temperature_scatter3d shows temperatures and locations in the US where the January temperature was recorded.

track_bar considers an eye-tracking experiment in which the eye was focused on different regions for different durations. Each region has a text label. A bar graph is desired, in which the bar for each duration is given the appropriate label.

volcano_fill creates a color-filled contour plot of a volcano's height, using an MxN table of data.

vortex_subplots displays a pair of subplots of the pressure and velocity vectors associated with a vortex flow.


Last revised on 30 September 2026.