Gnuplot (from Calc)
In this post, I show how to. Calc can be accessed with C-x * *
from anywhere in emacs.
Notes: to follow the examples below, you should install gnuplot on your system (installs separately) and have it accessible by emacs. Also, the mode of the calculator in these examples is in radians, the default is degrees. You can change this setting with m r
for radians and m d
for degrees from the calculator.
Plot the exponential function from 0 to 5
First the range of x-values
v x 5
Then get the y-values by copying the x
vector, then mapping with an exponential function
RET
v M E
Now g f
plots it. You plotted a curve with 8 keystrokes only.
Plot sin(x) from 0 to 2 pi
The range can define the smoothness of the curve, lets use pi/10
N: 41
START: -2 pi
INCR: pi/10
The input to the calculator is as follows
41 RET
0 RET P 2 * -
P 10 /
Now to get the range, use v x
with a numerical argument C-u
C-u v x RET
As before, copy the vector and map it
RET
v M S
g f
To get the plot.
Plotting several graphs on the same axis
To do this you need to use C-u g f
. Let’s plot the following from 0 to 5.
[x*exp(-x), x^2,*exp(-x), x^3*exp(-x)]
For the x values:
v x 5 RET
0 RET
TAB
v k
For the y values and plot:
v x 3 RET
v M ' x^n*exp(-x) RET (n) RET
C-u g f
Using algebraic mode
Plotting sine from -2 pi
to 2 pi
0 RET P 2 * -
P 2 *
C-u -6 v p
' sin(x) RET
g f
The numerical argument of -6
is to pack the first two entries to an interval. More information on packing modes here.
g a
adds a curve to the plot (opens a Gnuplots Commands buffer to edit the plot details if necessary).g h
edits the plot titleg t
edit the x labelg T
edits the y labelg p
plots