FE 'tkGooie' Utilities'PLOTtools' grouptkGnuplotXY_ upto3mathExpressionsa GUI 'front-end' for 'gnuplot'(FE = Freedom Environment) |
An XY plot from this FE 'tkGooie', a 'front end' to 'gnuplot' --- which plots up to 3 user-specified math expressions in a single plot (The width of the yellow plot line on the magenta 'canvas' background could have been specified more than 1 pixel wide via an entry on the tkGooie --- and the background could have been a lighter color, such as white) |
FE Home Page >
FE Downloads Page >
FE 'tkGooies' Description Page >
FE 'tkGooies' 'PLOTtools' Menu >
This 'tkGnuplotXY_ upto3mathExpressions'
tkGooie code Page
INTRODUCTION to On 2015 October 07, I provided a Tk script that uses 'gnuplot' to plot data from 2 or 3 columns of data in a file. I provided that 'gnuplot' 'front-end' Tk script at a 'tkGnuplotXY_file2or3cols' page of this site. On that page, I pointed out that it may be 2016 or so before I get around to getting some auto-plot-scaling and auto-ticmarking code into releasable form --- in some pure-Tcl-Tk 'PlotQuik' scripts that are on my 'to-do' list. I need to make that autoscale and auto-ticmarking code more robust (and modular). So, as a relatively quick-to-implement alternative, I decided to make some Tk GUI 'front-ends' for the popular, widely-available 'gnuplot' program --- some plot utilities for
The Tk script for item 1 above is posted in the page whose link is above. On this page, I present the code of a Tk script for item 2 above. 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 with regard to specifying and plotting math expressions. As I proceeded in the coding and testing, my knowledge of the capabilities of 'gnuplot' with regard to math-expression-plotting 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 at freedomenv.com, I made an initial '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 (if any).
* Vertical bars (and horizontal hyphens) outline a 'listbox' widget.
* Less-than and greater-than signs indicate the left and right ends of a horizontal 'scrollbar'.
* Capital-V and Capital-A letters indicate the bottom and top ends of a vertical 'scrollbar'.
Here is the sketch:
FRAMEnames
VVVVVVVVVV
------------------------------------------------------------------------------------------
Gnuplot of up to 3 math expressions:
[window title]
------------------------------------------------------------------------------------------
.fRbuttons {Exit} {Help} {RePlot} {Color of {Color of {Color of Load Expression: O 1 O 2 O 3
Lines} background} axes}
[.fRbottom FRAME contains the '.fRleft' and 'fRright' FRAMES]
[ '.fRleft' FRAME [ '.fRright FRAME'
is below ] is below and to the right ]
[FRAMES below
are in .fRright
-------------]
.fRexpr1 |---------------A Expression1: _________________________________________________________
| |
.fRexpr2 | [ This | Expression2: _________________________________________________________
| listbox |
.fRexpr3 | contains | Expression3: _________________________________________________________
| math |
.fRtitle | expressions ] | Plot title: __________________________________________________________
| |
.fRxaxis | | XaxisMin:______ XaxisMax:_______ XticLabelsAngle: ___ _____X-axis label______
| |
.fRyaxis | | YaxisMin:______ YaxisMax:_______ YticLabelsAngle: ___ _____Y-axis label______
| |
.fRlinetypes | | Expr1LineType(1-29): __ Expr2LineType(1-29): __ Expr3LineType(1-29): __
| |
.fRplotopts | | PlotType: O Line O Point O Both LineWidth(1-6): 1
| |
.fRoutopts | | ImageOutType: O GIF O PNG O JPG O PS O SVG {TestImg} Xpixels: 800__ Ypixels: 600__
| |
.fRmsg |<------------->V [ .......... Messages go here ......................................................]
From the GUI 'sketch' above, it is seen that the GUI is to consist of about
Here is an image of the GUI that I ended up with for a 'first release'. |
Poke this image to see the image
in a separate window or tab.
This is a little different from how the GUI appears when it intially appears. I had clicked on the 'Clear' button --- so a function, sin(x), that was in the 'Expression1' entry field was blanked out. Also I had done a plot, so you see the names of a couple of files (the gnuplot script file and the output image file) in the message line at the bottom of the GUI. It is also worth noting that by clicking the 'Autoscale' button, an asterisk is put into the four min,max entry fields. These asterisks are used to tell 'gnuplot' to automatically determine all four limits from the data chosen. 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. Anyone who wants to take the code on this page and alter the GUI to meet their needs is welcome to do it. This Tk GUI script is meant to be an actual 'productivity' tool (not a toy) --- a free and open-source tool --- a tool that is open to enhancement and 'tweaking'. 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 math-expressions, plot-title, and 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, radiobuttons and entry fields for 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 GUI 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 may sound like stating the obvious, it is probably worth mentioning that the 'listboxSelectionTOexprField' proc is called by a button1-release binding on the listbox --- and the 'replot' proc is called by the 'RePlot' button --- and the 'getset_*_color' procs are called by the 'Color' buttons. In a late addition to the GUI, I added the 'clear_expr' and 'set_autoscale' procs. The 'clear_expr' proc is called by the 'Clear' button, and the 'set_autoscale' proc is called by the 'Autoscale' button. The 'update_*_color_button' procs are called near the bottom of the Tk script to initialize the GUI, after initializing some color variables. And those 'update' procs are also called in the 'getset_*_color' procs. 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 a politician try to speak in complete, sensible sentences --- and fail repeatedly. (Who elects these people?) The Tcl-Tk script CODE Here is a link to CODE for the script 'tkGnuplotXY_upto3mathExpressions.tk'. You may find it instructive to see the variables set, in an 'Additional GUI Initialization' section near the bottom of the Tk script --- above the setting of the 'HELPtext' variable at the very bottom of the script. That section is where you can reset the viewers to be used, and change the middle-names and directory locations for the output files (gnuplot script and image files). The 'HELPtext' variable is set at the bottom of the script so that it can display the values of some of the variables that were set --- for example, the filename that was set for the output 'gnuplot' script file --- and the 'filename-prefix' that was set to be used in creating the name of an output gif/png/jpg/ps/psbw/svg file. Of course, if you need to change a directory name or want to change a middle-name for these files, you can simply change the 'set' statements that affect those names. Other 'gnuplot' utilities This is the second of several 'gnuplot front-end' utilities that I plan to write. Other Tk 'gnuplot front-end' scripts that may follow are:
A Sample 'Run': Below is output from one of my test runs. |
This is the 'eog' image file viewer utility
showing the plot of a linear combination of
sine and cosine functions, in a PNG file.
(I know. I should have chosen a better
color combination --- or at least used a
wider line width for the yellow.
Next time.)
The above plot colors (background-magenta and
plot-line-yellow) were set by this GUI.
You can see that the 'Color' buttons are colored
according to their current color setting.
This is what the 'update_*_color_button'
procs are for.
(Poke this image to see the image
in a separate window or tab.)
Sample terminal output from the gnuplot 'test' command: For those who have not seen the output of the 'test' command of 'gnuplot', for various terminal types, below are several images: |
This is 'gnuplot' 'test' command output was put in a
'.gif' file, because 'terminal gif' was requested.
NOTE:
All the line types are solid colors --- no dashes.
The same is true for 'terminal png' and 'terminal jpeg'.
Their output looks almost identical to this.
This is 'gnuplot' 'test' command output was
put in a '.ps' color-Postscript file, because
'terminal postscript landscape color colortext'
was requested.
NOTE:
Many dashed line types are available
when terminal postscript-color is requested.
This is 'gnuplot' 'test' command output was
put in a '.ps' monochrome-Postscript file, because
'terminal postscript landscape mono blacktext'
was requested.
NOTE:
Many dashed line types are available
when terminal postscript-mono is requested.
The two Postscript 'gnuplot-test' images above were
displayed on Linux with the 'evince' PDF/Postscript viewer.
Each of those screen images were captured with the
'gnome-screenshot' program into a PNG file.
The PNG file was cropped with the 'mtpaint' image
editor program. The 'mtpaint' program saves to quite
large PNG files, so the 'pngcrush -brute' command
was used to minimize the PNG file size.
This is 'gnuplot' 'test' command output that was
displayed in a 'gnuplot' 'wxt' terminal, after
'terminal wxt persist' was requested.
NOTE: No dashed line types.
This screen capture of the 'wxt' terminal window
was done with the 'gnome-screenshot' program,
to a '.png' file.
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.
Below is the gnuplot script file that was created and executed after clicking on the 'TestImg' button with GIF output selected. Notice the simple 'test' command. |
#!/usr/bin/gnuplot
! cd /tmp
set terminal gif size 600 , 400
set output '/tmp/${USER}_temp.gif'
test
! /usr/bin/eog /tmp/${USER}_temp.gif &
Future Enhancements: I have not tested this Tk-GUI script extensively. No doubt, if I use it some more, I will find a few things to change, add, or fix. I MAY add more example functions to the listbox, someday. Furthermore, as I point out at the bottom of the 'HELPtext', 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 In case those pages disappear, here are a couple of images that show what Zoltan was able to achieve --- using some tricky 'gnuplot' commands: |
A color-gradient background done with
'gnuplot' commands, to a 'wxt' terminal.
A 'shadow curve' plot done with
'gnuplot' commands, to a 'wxt' terminal.
This just goes toward showing:
|
UPDATE - 2015oct14: I have replaced the Tcl-Tk code at the link above with code that implements a few minor enhancements. Main changes are:
You can see an image of the new GUI when it first comes up, just below --- with 3 math expressions in the 3 expression entry fields. |
Note that although the GUI looks quite 'busy', when it first comes up, the user can simply click the 'RePlot' button to immediately get a plot, using the initial GUI settings. Then the user can start changing parameters to get at a desired plot. I know that many operating systems are going for an 'ultra-clean' look --- hiding most options. That is frustrating to me. For one thing, it is typically not clear where to look to find ANY of the operating options, even a Help option. I prefer having as many options 'exposed' as possible. I do not like clicking through drop-down menus trying to find options. Having the options exposed to immediate usage means many fewer clicks during a work session. Below is the gnuplot script file that was created in one of my test runs. Note the f(x), g(x), and h(x) functions. |
#!/usr/bin/gnuplot
! cd /tmp
set terminal wxt persist title "WXT terminal window"
set title 'exp(-x/10.0)*sin(x)'
set timestamp '%Y %b %d %a %H:%M:%S'
set xlabel ' X-axis TITLE goes here.'
set ylabel ' Y-axis TITLE goes here.'
set xrange [ * : * ]
set yrange [ * : * ]
set xtics rotate by 0
set nomxtics
set ytics rotate by 0
set nomytics
set xzeroaxis
set yzeroaxis
set nokey
f(x) = exp(-x/10.0)*sin(x)
g(x) = exp(-x/10.0)
h(x) = -exp(-x/10.0)
plot [*:*] f(x) with lines linewidth 1 linecolor rgb '#FF0000' linetype 1 \
, g(x) with lines linewidth 1 linecolor rgb '#FF0000' linetype 2 \
, h(x) with lines linewidth 1 linecolor rgb '#FF0000' linetype 3
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 which 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. |
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. OR ...
< Go to Top of Page, above. >Page history:
This FE web page was created 2015 Oct 09.
NOTE: |