how to customise plot title in spatstat - spatstat

How may I change the plot titles and subtitles when using plot command on linnet object. For example
library(spatstat)
first = runiflpp(10, as.linnet(chicago), nsim = 2)
plot(first)
This code above gives two realisations of a a point process and a plot with the plot command because we requested for nsim=2. But it plots the two realisations with plot title 'simulation 1' and 'simulation 2'.
How can I change the subplot titles for example from simulation 1 to experiment 1?
thank you

The simplest way would be to change the names of the items in the list:
names(first) <- paste("experiment", 1:2)
Alternatively you can change the argument main.panel in plot.solist (see ?plot.solist for all the options):
plot(first, main.panel = paste("experiment", 1:2))

Related

How to remove legend being taken as a dimension in python plot

So I wish to Plot the pairwise scatter plot with hue dimension of the grid.
But legend which is :1 and :2 is also getting displayed along other labels.I guess it is taking 1 and 2 as numbers not as legend strings.
Here is my code:
plt.close();
sns.set_style("whitegrid");
x = sns.pairplot(data, hue="status", height=2.5);
plt.show()
This is the output I am getting:
I wish to remove status being taken as a dimension
Since you do not want all the variables to be plotted, you should specify which ones you want. That is done with the vars argument:
x = sns.pairplot(data, vars=['age', 'years', 'nodes'], hue="status", height=2.5);
plt.show()

Gnuplot 3d time animation from data file

I realise this is perhaps trivial and if I had more time I'd probably easily deal with it myself, but I'm running out of time and I desperately need to get this animation working as soon as possible.
I have data file of the type
0 28.3976 25.1876 12.7771
0.03125 34.1689 21.457 9.70863
0.0625 35.7084 17.6016 5.03987
0.09375 34.3048 13.6718 1.45238
...
where the first column is meant to be treated as time (it is in fact a numerical solution to a certain ODE system). Now. what I need is an animation of a 3d plot of the last three columns tracing a curve as it moves around with time. Is that doable? If so, how? I'm a complete gnuplot beginner and googling around did not help much. I would hugely appreciate any help. Cheers!
The following should show you an animated plot:
# define fixed axis-ranges
set xrange [-1:1]
set yrange [0:20]
set zrange [-1:1]
# filename and n=number of lines of your data
filedata = 'data.dat'
n = system(sprintf('cat %s | wc -l', filedata))
do for [j=1:n] {
set title 'time '.j
splot filedata u 2:3:4 every ::1::j w l lw 2, \
filedata u 2:3:4 every ::j::j w p pt 7 ps 2
}
The first line of the splot command plots the trayectory, and the second line plots the point at the current time.
If you want a gif of this output, simply add the following before the for-loop:
set term gif animate
set output 'output.gif'
This is an example output:
Related:
StackOverflow: Gif Animation in Gnuplot
gnuplot-surprising: creating gif animation
gnuplotting: Animation IV – trajectory

plotting a 3D+colour scatter with gnuplot (on torch7)

I'm working with torch7, and I created a PCA function, which gives me an Nx3 tensor which I wish to plot (3D scatter).
I stored it in a file (file.dat).
now I want to plot it, I wrote the following lines
NOTE: those lines are in torch7(lua), but you don't really need to know the language, because the command gnuplot.raw("<command>") uses the regular gnuplot commands.
NOTE 2: I followed helpers on this forum to create this part, I probably read a relevant thread you might want to link here. If you do, please explain what's the difference between the linked explanation an what I did
gnuplot.raw("rgb(r,g,b) = 65536*r + 256*g + b")
gnuplot.raw("blue = rgb(0,0,200)")
gnuplot.raw("red = rgb(200,0,0)")
gnuplot.raw("layer = 1")
gnuplot.raw("splot './file.dat' using 1:2:3:(($4-layer)<0.1 ? red : blue) with points pt 7 linecolor rgb variable notitle")
cols 1 through 3 in file.dat are the x,y,z coordinates, col 4 is either 1 or 2 (determines colour).
LAST NOTE: my script doesn't print an error of any kind, it just doesn't plot the desired 3D scatter.
Thanks ahead

Gnuplot: Plotting trajectories of multiple objects in separate blocks

I compute the iterated positions of multiple particles, so that my output file looks like :
x1(t=0) y1(t=0)
x2(t=0) y2(t=0)
...
xn(t=0) yn(t=0)
x1(t=1) y1(t=1)
...
xn(t=1) yn(t=1)
(a lot of blocks)
x1(t=p) y1(t=p)
...
xn(t=p) yn(t=p)
For example, the particle 1 is on each first line of a block, etc.
I need to plot the trajectory of each particle in a single plot, with points linked with lines. The problem I stumble upon is to link properly the points corresponding to the correct particle. I found some advice recommending to reformat the data but I have no idea how to handle it. It might be also possible to plot directly the trajectories with a plot command but once again I am low on solutions.
You should be able to do it with a loop (in gnuplot >= 4.6) and the index option to the plot command:
p = (number of particles)
plot for [i=0:p] 'data.dat' index i with linespoints
The with linespoints option also sounds like what you want, which links the data points with lines.
Unfortunately, there is no way to do this with your current datafile setup. You can make a plot which doesn't connect the points using the every (e) keyword:
plot for [i=0:NPOINTS-1] 'test.dat' e ::i::i w p
But, that's not very helpful really if you want the datasets connected, you need to "invert" your data. I'd use python because it's super easy:
#pythonscript.py
import sys #allow us to get commandline arguments
#store data as
#[[x1(t=0) y1(t=0),x2(t=0) y2(t=0),x3(t=0) y3(t=0),...],
# [x1(t=1) y1(t=2),x2(t=2) y2(t=2),x3(t=2) y3(t=2),...],
# ...
# [x1(t=N) y1(t=N),x2(t=N) y2(t=N),x3(t=N) y3(t=N),...],
#]
with open(sys.argv[1]) as fin:
data = []
current = []
data.append(current)
for line in fin:
line = line.rstrip()
if line:
current.append(line)
else:
current = []
data.append(current)
#now transpose the data an write it out. `zip(*data)` will give you:
#[(x1(t=0) y1(t=0),x1(t=1) y1(t=1),x1(t=2) y3(t=2),...),
# (x2(t=0) y2(t=0),x2(t=1) y2(t=1),x2(t=2) y2(t=2),...),
# ...
# (xN(t=0) yN(t=0),xN(t=1) yN(t=1),xN(t=2) yN(t=2),...),
#]
for lst in zip(*data):
for dpoint in lst:
print dpoint
print
For me, given the input file (test.dat):
x1(t=0) y1(t=0)
x2(t=0) y2(t=0)
xn(t=0) yn(t=0)
x1(t=1) y1(t=1)
x2(t=1) y2(t=1)
xn(t=1) yn(t=1)
x1(t=p) y1(t=p)
x2(t=p) y2(t=p)
xn(t=p) yn(t=p)
running python pythonscript.test.dat gives:
x1(t=0) y1(t=0)
x1(t=1) y1(t=1)
x1(t=p) y1(t=p)
x2(t=0) y2(t=0)
x2(t=1) y2(t=1)
x2(t=p) y2(t=p)
xn(t=0) yn(t=0)
xn(t=1) yn(t=1)
xn(t=p) yn(t=p)
Now you can plot that using the solution by andyras:
plot for [i=0:NP] '< python pythonscript.py data.dat' index i w lp

how to output dots/arrows at the ends of line

I am new to gnuplot, I need to plot my data and display a small circle or an arrow at each end of the line chart. how can I do that?
I use this command to display the line chart:
plot 'data.txt' with lines
I don't know if there is a way to make lines have something at the end automatically, but I found a workaround. With this data file:
1 1
2 3
3 2
and the following script:
set term png
set out 'plot.png'
stats 'data.dat' name 'a'
# plot line, then circle only if it is the last data point
plot 'data.dat' t 'data', \
'' u ($0==(a_records-1)?$1:1/0):2 with points pt 7 ps 2 t 'end'
I can make a plot like this:
The stats command is to find the number of data points, then the dual plot command draws the line connecting the data points, then a circle only on the last data point (determined with the a_records variable. An arrow would be trickier to draw...
To find more info about different point/line style options, the test command at the gnuplot command line is your friend.

Resources