Friday, December 8, 2017

GNUplot plotting examples

The following illustrates 2-dimensional plotting of functions of a single variable, f(x), i.e. plotting f(x) versus x:

============= 
#!/gnuplot
#               gnuplotex1.plt batch file   
set xlabel "x"
set ylabel "f(x)"
set title "gnuplotex1"
plot [0:2*pi] x,exp(-x),x*sin(x)
set term png
set output "./gnuplotex1.png"
replot
=============

And the output from this is:


One can see that the three plots are superimposed. The range of the independant variable, x, is set by the expression in square brackets, [0:2*pi] (we could have written [0:2*3.15159] had we so wished).


Next, we plot t he same functions in pseudo-3D, i.e.,
=============
#!/gnuplot
#               gnuplotex2.plt batch file
set xlabel "x"
set ylabel "f(x)"
set title "gnuplotex2"
splot [u=0:2*pi] u,exp(-u),u*sin(u)
set term png
set output "./gnuplotex2.png"
replot
=============


We add a line now, to change the plot completely:
=============
#!/gnuplot
#               gnuplotex3.plt batch file     
set parametric
set xlabel "X-axis"
set ylabel "Y-axis"
set zlabel "Z-axis"
set title "gnuplotex3"
splot [u=0:2*pi] u,exp(-u),u*sin(u)
set term png
set output "./gnuplotex3.png"
replot
=============
Example 2 with "set parameter" added.
The plot has changed dramatically, and is very hard to understand. Here are three views of the same example, this time oriented so as to aid understanding:
=============
#!/gnuplot
#               gnuplotex3a.plt batch file
reset
set term wxt  persist
set parametric
set xlabel "X->u"
set ylabel "Y->exp(-u)"
set zlabel "Z-axis->u*sin(u)"
set title "gnuplotex3a (approximately the Z-X plane)"
set view 90,0
splot [u=0:2*pi] u,exp(-u),u*sin(u)
set term png
set output "./gnuplotex3a.png"
replot
=============
Looking down the "Y" axis.

and
=============
#!/gnuplot
#               gnuplotex3b.plt batch file
reset
set term wxt  persist         
set parametric
set xlabel "X->u"
set ylabel "Y->exp(-u)"
set zlabel "Z-axis->u*sin(u)"
set title "gnuplotex3b (approximately the Z-Y plane)"
set view 90,90
splot [u=0:2*pi] u,exp(-u),u*sin(u)
set term png
set output "./gnuplotex3b.png"
replot
=============
Looking down the "X" axis.
This is a really weird plot, since one axis is not an axis actually, but another function.

Finally
=============
#!/gnuplot
#               gnuplotex3c.plt batch file
reset
set term wxt  persist           
set parametric
set xlabel "X->u"
set ylabel "Y->exp(-u)"
set zlabel "Z-axis->u*sin(u)"
set title "gnuplotex3c (approximately the X-Y plane)"
set view 0,90
splot [u=0:2*pi] u,exp(-u),u*sin(u)
set term png
set output "./gnuplotex3c.png"
replot
=============
Looking down the "Z" axis.

Actually, this last one is "upside-down" in that the vertical axis is reversed from the normal presentation mode.

I would like to actually have the plot rotate using the mouse, but to do this from a batch file seems impossible (see this discussion). What I've had to do is copy the text of the batch file, and then paste it into the terminal which is running gnuplot. Then, and only then, using the mouse one can orient the plot and decide about the angles to be used with the 'set view' command. If anyone can help clarify this, please write me.

Sunday, November 12, 2017

Linux/ubuntu 17.11 and xfig or inkscape

The conversion to ubuntu 17.11 goes smoothly, but regaining access to programs such as xfig, inkscape, and octave requires some small effort. Here’s what i did:

  1. In the lower left corner of the desktop is an array of dark squares, and when activated shows you programs not included in the dock. Find and choose “terminal”.
  2. In the terminal, type, for example “xfig” (without the quotes)
  3. Enter the sudo command the system suggests. Et. voila!
Perhaps there are better ways.

In any case, neither octave nor gnuplot worked properly, and I asked the Ubuntu forums for herlp. Here is what I got back:

This error can be solved by changing line 30 in /usr/share/themes/Ambiance/gtk-2.0/apps/mate-panel.rc as shown below. Open the terminal and type:
sudo -i  
cd /usr/share/themes/Ambiance/gtk-2.0/apps  
cp mate-panel.rc mate-panel.rc.bak # backup mate-panel.rc file before editing it  
nano mate-panel.rc
Now mate-panel will be open for editing in nano text editor. Scroll down with the  key and change the following line:
class "GtkScrollbar"              style "murrine-scrollbar" 
by replacing the string "murrine-scrollbar" with "scrollbar" so that it looks like this:
class "GtkScrollbar"              style "scrollbar"  
Press the keyboard combination Ctrl+O and after that press Enter to save the changes in mate-panel.rc. Press the keyboard combination Ctrl+X to exit nano.
Logout in the terminal from root back to normal user.
exit 
Now you will be able to use gnuplot and Octave without getting an error message that says: error: invalid string constant "murrine-scrollbar", expected valid string constant

The anonymous answerer was "karel". And the good news is that this worked exactly as presented. What a wonderful Ubunutu world!

Tuesday, July 25, 2017

RevTex and Weavr and included figures

Weavr is a logical successor to SpartanTex which was a free LaTeX service using a cloud installation of LaTex rather than maintaing one’s own version.

The following text which constitutes a complete file, compiles properly using Weavr into a document. This means one can store one's LaTeX manuscripts (including RevTex based manuscripts) on Google Drive (Docs) and use Weavr to process them. However, one does not obtain intermediate files which have to be submitted with or inside LaTeX submissions for journal publication.

In any case, here is the Google file:

==================BEGIN OF COMPLETE WEAVR FILE==================

<<input.tex>>=
\documentclass[eqsecnum,aps]{revtex4-1}
\usepackage{graphicx,cancel,framed,ulem,braket}
\begin{document}
\title{Weavr Illustration and Bibliography using RevTex}
\author{it doesn’t matter}


\affiliation{University t\\
Department of Something, Emeritus\\
}
\date{\today}
\maketitle


\section{Poems}
\begin{quotation}
Be not sad because all men\\
Prefer a lying clamour before you:\\
Sweetheart, be at peace again -- - \\
Can they dishonour you?\\
\\
They are sadder than all tears;\\
Their lives ascend as a continual sigh.\\
Proudly answer to their tears: \\
As they deny, deny
\cite{joyce}.
\end{quotation}


Or\\
\begin{figure[h]}
\fbox{<<pointer1>>}
\caption{An illustration.}
\label{fig1}
\end{figure}


Or


\begin{quotation}
Twas brillig, and the slithy toves\\
Did gyre and gimble in the wabe; \\
All mimsy were the borogoves, \\And the mome raths outgrabe. \\
Beware the Jabberwock, my son \\
The jaws that bite, the claws that catch\cite{Carroll}!
\end{quotation}





\bibliographystyle{apsrev4-1}
\bibliography{abib.bib}

\end{document}
@


<<abib.bib>>=


@article{joyce,
  author = "Joyce, J.",
  journal = "Reprtinted Everywhere",
  volume = "18",
  year =1905
}
@article{Carroll,
  author = "Carroll, L.",
  journal = "Through the Looking Glass",
  volume = "Jabberwocky",
  year =1871
}


@


<<pointer1>>=
\includegraphics[width=5in]{fig1.png}
@
<<fig1.png>>=
@





==================END OF COMPLETE WEAVR FILE==================

Almost all of the above can be cut and pasted into a Weavr created file on Google Drive and it should compile properly into a pdf-file. The pictures will not work, I think. Of course, the greater than and less than symbols may need editing. And don't forget that files referenced which reside on Google Drive need to have their permissions set properly for "remote" access.

Notice that this is easier than the WEAVR documentation method (for figures) which ceased working during my last efforts. This method imports the documents directly into the WEAVR file for submission to the LaTeX engine. Also, it seems to me that this method allows verification that the figures are the ones intended (compared to a web address).

If there is any error here, please contact me. Thanks.




====================================NEXT=====================


Saturday, July 22, 2017

Using Weavr for online LaTex composing (obsolete, use overleaf.com)

This is not a programming post. instead, it is a LaTeX post in support of Weavr, the on-line service which allows users to use Google Docs for Latex .tex (and .bib) storage and Weavr as a front-end for compiling and generating PDFs.
By being cloud based, one need not maintain a local version of LaTeX nor need one maintain local versions of LaTeX input files.



A special thanks to Neil Crawforth who answered my questions in record time with perfect answers.

I had two major questions concerning Weavr, and cutting and pasting the help from the site proved impossible (for me). The first question concerned including figures, and the solution is shown below:


<<input.tex>>=
\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}
\begin{document}
BEFORE
\colorbox{yellow}{<<My pointer>>}
AFTER
\end{document}
@
<<My pointer>>=
\includegraphics[width=4in]{GS.png}
@
<<GS.png>>=
@


The second example uses BibTex, a common tool for academic writing:




<<input.tex>>=
\documentclass[11pt]{article}
\usepackage{cite}
\begin{document}
\title{My Article}
\author{Nobody Jr.}
\date{Today}
\maketitle
Normal text\footnote{taken in part from \url{http://www.bibtex.org/Using/}}
\bibliographystyle{plain}
\end{document}

with a reference: Nobody ~\cite{Nobody06},
which comes out as one expects (hopes?).
For blogging purposes, the bibliography will be maintained on Google Docs so that cutting and pasting this document should refer to the same bibliography.
\bibliography{mybib.bib}{}
@
<<mybib.bib>>=
<<https://docs.google.com/document/d/1JkbtbAcNCNdWSB0x3lx-PAA9P9GIhlAPHzeCmpAmhqo>>
@


Each of these is a complete unit, contained in one file on Google Docs, and compiled by Weavr upon command.


I hope that these are helpful in easing the pain of transitioning to Weavr (which I find incredible).
In both cases, the url's are to actual files which exist on my Google Docs drive. 

Remember, external docs on Google Docs need to he shared with Weavr.co.uk so that it can be remotely accessed.

Be warned that cutting and pasting from this post may require editing of right and left angle brackets (greater than and less than) from HTML to actual representations.

If there is an error (above) or lack of clarity in the material (above), please tell me.