FE 'tkGooie' Utilities'PLOTtools' grouptkGnuplotXY _logORloglog _file2or3colsa GUI 'front-end' for 'gnuplot'(FE = Freedom Environment) |
![]() An X-logY plot from this FE 'tkGooie' 'front end' to 'gnuplot' --- which reads 2 or 3 data columns from a text file and does an X-logY or a logX-logY plot |
FE Home Page >
FE Downloads Page or
FE Overview Page >
FE 'tkGooies' Description Page >
FE 'tkGooies' 'PLOTtools' Menu >
This 'gnuplot' Log-or-LogLog Plot
'tkGooie' code Page
INTRODUCTION to On a tkPiePlot page of this site, I describe a personal commitment to donate about five 'PlotQuik' utilities (Tk scripts) to the Tcl-Tk wiki at wiki.tcl.tk. Since it may be late 2016 or 2017 or so before I get around to making some auto-plot-scaling and auto-ticmarking code in those scripts more robust (and modular), I have decided to make some Tk GUI 'front-ends' for the popular, widely-available 'gnuplot' program --- some plot utilities for
Items 1, 2, 3, and 4 have been published at other web pages of this site. Those pages are accessible via the several links above. I have written a Tk script for making log and log-log plots with gnuplot. That is the subject of this page. The code is presented further below. THE GOALS I had some general goals for the Tcl-Tk 'front-end' script for this GUI. Those goals were shaped by the capabilities of the 'gnuplot' program. As I proceeded in the coding and testing, my knowledge of the capabilities of 'gnuplot' advanced, and some of my goals were augmented or altered. Here are the main goals to which I gravitated.
THE GUI LAYOUT Like for some other Tk GUI scripts that I posted here, I made a 'text-sketch' for the GUI for this 'gnuplot' 'front-end' utility. |
CONVENTIONS for the GUI 'text-sketch' below:
* SQUARE-BRACKETS indicate a comment not to be included on the GUI.
* BRACES indicate a Tk 'button' widget.
* UNDERSCORES indicate a Tk 'entry' widget.
* A COLON indicates that the text before the colon is on a 'label' widget.
* CAPITAL-O indicates a Tk 'radiobutton' widget.
* CAPITAL-X indicates a Tk 'checkbutton' widget.
Here is the sketch:
FRAMEnames
VVVVVVVVVV
------------------------------------------------------------------------------------------
Gnuplot LOG or LOG-LOG plot of 2 or 3 columns from a data file:
[window title]
------------------------------------------------------------------------------------------
.fRbuttons {Exit} {Help} {Plot} {Color of {Color of {Color of X SameAxisUnits for Y1,Y2
Lines} axes} background}
.fRfile Data Filename: _______________________________________________ {Browse...}
.fRtitle Plot title: _________________Plot title goes here._____________________________________________________
.fRlogtype Log axes: O x O y O xy O neither
.fRxaxis XColumn: 1__ XaxisMin ______ XaxisMax _______ XticLabelsCol#: __ _____X-axis label goes here____
.fRy1axis Y1Column: 2__ Y1axisMin ______ Y1axisMax _______ LineType(1-29): __ _____Y1-axis label goes here___
.fRy2axis Y2Column: ___ Y2axisMin ______ Y2axisMax _______ LineType(1-29): __ _____Y2-axis label goes here___
.fRplotopts PlotType: O Line O Point O Both LineWidth(1-6): 1 X Grid? X Border?
.fRtics XticLabelsAngle: ___ YticLabelsAngle: ___ X Minor Tics?
.fRoutopts Image file type: O GIF O PNG O JPG O PSc O PSbw O SVG O WXT {TestImg} Xpixels: 800__ Ypixels: 600__
.fRmsg [ .......... Messages go here ......................................................]
From the GUI 'sketch' above, it is seen that the GUI consists of about
Here is an image of the GUI that I ended up with for a 'first release'. |
As I use this utility, I may find that I want to alter the GUI somewhat. If I make some significant changes, I intend to replace the script file here with the new file. This GUI is not meant to be a toy or simply a demo. The LOG-plot of world population data shown (reduced) at the top of this page indicates that this Tk GUI is meant to be an actual 'productivity' tool --- a free and open-source one --- a tool that is open to enhancement and 'tweaking'. --- In this example of world-population growth, note that a y-log plot of simple exponential growth would appear as a SINGLE STRAIGHT LINE angled upward in the plot. However, this plot indicates that world-population growth exhibits a bi-exponential or tri-exponential growth pattern.
BI-EXPONENTIAL: The faster growth from about 1800 may be attributed to discoveries in microbiology thanks to the microscope and other new instruments and techniques --- in particular, discovery of bacterial and parasitic disease causes --- and discovery of ways to curb such diseases through better sanitation, better food preparation and storage, avoidance of risky situations, etc.
TRI-EXPONENTIAL: The growth spurt after 1950 might be attributed to the discovery and widespread distribution of vaccines to combat diseases such as smallpox, polio, diptheria, whooping cough, tetanus, mumps, and measles --- and the roll-out of much better sewage, drainage, and water-treatment facilities and the ramped up manufacture and distribution of window and door screens and glass windows and doors. Below is the original 600 x 400 pixels plot image for better examination. There are some dips in world population in the years between 1300 to 1700. If we assume that the data for that time (although based on estimates for various countries) is basically correct, the 1300-to-1700 data indicates the devastation caused by some plagues --- when large urban centers experienced diseases spreading quite rapidly to large numbers of people when knowledge-of-cause (what to avoid) and effective-cures (for those already afflicted) were not available. |
In summary, the log plot indicates some subtleties of the world-population data that is not apparent in a non-log plot. Back to the code for this utility ... DESCRIPTION OF THE CODE Below is a link to the code that produced this GUI. I follow my usual 'canonical' structure for Tk code, for this Tk script: |
0) Set general window & widget parms (win-name, win-position,
win-color-scheme, fonts, widget-geometry-parms, win-size-control).
1a) Define ALL frames and sub-frames.
1b) Pack ALL frames and sub-frames.
2) Define & pack all widgets in the frames.
3) Define keyboard or mouse/touchpad/touch-sensitive-screen
action BINDINGS, if needed.
4) Define PROCS, if needed.
5) Additional GUI initialization (typically with one or more of
the procs), if needed.
This Tk coding structure is discussed in more detail on the page A Canonical Structure for Tk Code --- and variations. This makes it easy for me to find code sections --- while generating and testing Tk scripts, and when looking for code snippets to include in other Tk scripts (code re-use). Experimenting with the GUI As in all my scripts that use the 'pack' geometry manager (which is all of my 100-plus Tk scripts, so far), I provide the four main 'pack' parameters --- '-side', '-anchor', '-fill', and '-expand' --- on all the 'pack' commands for the frames and widgets. I think I have found a good setting of the '-side', '-anchor', '-fill', and '-expand' parameters on the 'pack' commands for the various widgets of this GUI. In particular ... The filename, plot-title, axis-titles entry widgets expand/contract appropriately when the window size is changed --- and button and label widgets stay fixed in size and relative-location as the window size is changed. Furthermore 'entry' fields for column-numbers, axis-limits, line-width/types, and pixel-sizes stay fixed in size. If anyone wants to change the way the GUI configures itself as the main window size is changed, they can experiment with the '-side', '-anchor', '-fill', and '-expand' parameters on the 'pack' commands for the various widgets --- to get the widget behavior that they want. --- Additional experimentation: You could change the fonts used for the various GUI widgets. For example, you could change '-weight' from 'bold' to 'normal' --- or '-slant' from 'roman' to 'italic'. Or change font families. In fact, you may NEED to change the font families, because the families I used may not be available on your computer --- and the default font that the 'wish' interpreter chooses may not be very pleasing. Furthermore, there are variables used to set geometry parameters of widgets --- parameters such as border-widths and padding. Feel free to experiment with those parameters as well. --- Note that the 3 'Color' buttons call on an RGB color-selector-GUI script to set the colors. You can make that color-selector script by cutting-and-pasting the code from the page offering 'a non-obfuscated color selector GUI', on this site. Some features of the code There are plenty of comments in the code to describe what most of the code-sections are doing. See the 'PROCS' section of the code to see the code in all the procs that are used in this Tk script. The main plotting code is in the proc 'replot'. See the comments in that proc for details on how the plotting is implemented by creating a 'gnuplot' script of commands to pass to the 'gnuplot' program. Here is a list of the procs in this Tk script:
Although it sounds like stating the obvious, it is probably worth mentioning that the 'get_filename' proc is called by the 'GetFilename' button, and the 'replot' proc is called by the 'RePlot' button --- and the 'getset_color' proc is called by the 'Color' buttons. The 'update_color_button' proc is called (once for each color button) near the bottom of the Tk script to initialize the GUI, after initializing some color variables. And the 'update_color_button' proc is also called in the 'getset_color' proc. Just a few more comments on some 'features' of this script:
Comments in the Code It is my hope that the copious comments in the code will help Tcl-Tk coding 'newbies' get started in making GUI's like this. Without the comments, potential young Tcler's might be easily frustrated and be tempted to return to their iPhones and iPads and iPods --- to watch how celebrities are mis-behaving . . . while the really 'lasting', significant stuff is being done by inventors, researchers, engineers, scientists (physicists, chemists, biologists, etc.), architects, and millions of crafts-people and manufacturers, including carpenters, electricians, plumbers, iron-workers, bridge-builders, tunnel-builders, etc. (Try the Science channel for some really interesting programming --- like the "How It's Made" and "How the Universe Works" and "Outrageous Acts of Science" series.) The Tcl-Tk script CODE Here is a link to CODE for the script 'tkGnuplotXY_logORloglog_file2or3cols.tk'. And here is a link to a SAMPLE DATA file 'gnuplot_DATA_world_population.txt'. I have most of the entry field variables set, in an 'Additional GUI Initialization' section near the bottom of the Tk script, to accomodate this test file when you first try this Tk GUI. Other 'gnuplot' utilities This is the fifth of several 'gnuplot front-end' utilities that I had planned to write. See the links to 4 others at the top of this page. I still have a few more in mind. Other Tk 'gnuplot front-end' scripts that may follow are:
Future Enhancements: I have not tested this script extensively. No doubt, if I use it some more, I will find a few things to change, add, or fix. I pointed out, above, that I may someday implement the 'Same Scale for Y1,Y2' checkbutton. In that case, if a user unchecks the button, several entry fields on the GUI would be changed from 'disabled' mode to 'enabled' mode. For example, the Y2 min,max entry fields and the Y2 axis label entry field would be enabled. 'gnuplot' TERMINAL TYPES: I have provided for most of the 'gnuplot' 'terminal types' for output. Note that I have provided for 2 types of Postcript output --- color and black-and-white. The 'PSc' option implements 'terminal postscript landscape color colortext'. The 'PSbw' option implements 'terminal postscript landscape mono blacktext'. Furthermore, I have enabled the 'WXT' terminal type. The 'wxt' terminal uses the wxWidgets library, which is where the 'wx' comes from. The actual drawing is done via Cairo, a 2D graphics library, and Pango, a library for laying out and rendering text. The 'wxt' terminal may offer the ability to get some high-quality output, because it may offer better quality lines and text (perhaps due to better anti-aliasing). However, the 'wxt' terminal does not write to an image file. The output is put in a terminal window. To get an image file, the user can use a screen-capture utility (such as 'gnome-screenshot' on Linux) to get the image in a PNG file. Then an image editor (such as 'mtpaint' on Linux) can be used to crop and resize the image file, if necessary. And a command like 'pngcrush -brute' can be used to minimize the size of the final PNG file. At this time (2016 Feb), I do not plan to add anymore 'terminal types' to the GUI. As I point out at the bottom of the 'HELPtext' for this Tk script, someday I may try to get more appealing plots --- with color gradient backgrounds and with 'shadow curves' and with 'ribbon curves' --- by using some of the 'gnuplot tricks' of Zoltan Voros, that can be seen at 'www.phyast.pitt.edu/~zov1/' in If those pages are no longer available, you can see a couple of examples of that high-quality 'gnuplot' output at the bottom of a page on a Tk GUI Front-End for 'gnuplot' - for generating MATH EXPRESSION xy-plots - allowing for up to 3 math expressions on a plot. By the way, here is the gnuplot script file that was created in one of my test runs. |
#!/usr/bin/gnuplot
! cd /tmp
set terminal gif size 600 , 400 nocrop noenhanced butt xFFFFFF x000000 x000000
set output '/tmp/userid_temp.gif'
set title ' World Population (year 1 to 2000)'
set timestamp '%Y %b %d %a %H:%M:%S'
set xlabel ' Year'
set ylabel ' World Population (millions)'
set logscale y
set xrange [ * : * ]
set yrange [ * : * ]
set xtics rotate by 0
set ytics rotate by 0
set xzeroaxis
set yzeroaxis
set border 15
set nokey
plot '...a filename goes here ...' using 1:2 with lines linewidth 1 linecolor rgb '#FF0000' linetype 1
! /usr/bin/eog /tmp/userid_temp.gif &
The 'set logscale y' command is the command that is essential to this log-plot utility. It calls for a log-scale on the y-axis. This is pretty crisp and clean, compared to all the comments that I have around the Tcl-Tk code that is writing out these gnuplot commands. Note that by using the Tk GUI, the user can typically avoid having to page back and forth through 'gnuplot' documentation trying to find commands to use and the proper syntax for those commands --- and parameters to use with those commands. And the user avoids many syntax errors, because I filtered out the errors that I made during testing, resulting in gnuplot commands that are probably going to work --- with gnuplot 4.2 and thereafter. Essentially all of a user's documentation searching and syntax debugging is eliminated by use of this Tk GUI. Thanks (again) On many of my 'tkGooie' code donation pages, I have said ... There's a lot to like about a utility that is 'free freedom' --- that is, no-cost and open-source so that you can modify/enhance/fix it without having to wait for someone else to do it for you (which may be never). A BIG THANK YOU to Ousterhout for starting Tcl-Tk, and a BIG THANK YOU to the Tcl-Tk developers and maintainers who have kept the simply MAH-velous 'wish' interpreter going. |
Bottom of this web page for
To return to a previously visited web page location, click on the
Back button of your web browser a sufficient number of times.
OR, use the History-list option of your web browser.
< Go to Top of Page, above. >Page history:
This FE web page was created 2016 Feb 02.
NOTE: |