I want to do multiple plots related to differents data columns of the same file but I want a new window for each plot. I don't want attached plots associated to the command set multiplot layout 1,2.
The idea is represented by the following pseudocode:
>gnuplot
>plot "myfile.txt" u 1:4
>#make me plot another file without deleting the previous one i.e. open a new window on which data is plotted
>instructions I don't know
>plot "myfile.txt" u: ($3*$3)
>#I obtain two windows
You don't write which terminal you are using. I understand you want to have two windows next to each other, and not two graph as file on disk. In gnuplot console check for example: help wxt. In case you want two files on disk you have to select another terminal, e.g.
set term pngcairo
set output 'myOutput1.png'
plot x
set output 'myOutput2.png'
plot x**2
set output
So with the interactive wxt terminal the following works for me:
Code:
### several terminals
reset session
set term wxt 1 size 500,400
plot sin(x)
set term wxt 2 size 500,300
plot cos(x)
set term wxt 3 size 300,200
plot x**2
### end of code
Result:
Related
Create a plot with cars dataset and attribute speed along the X axis and distance in y axis .
Label the axes.
I have done this programming still there is some problem:
plot(cars,xlab="speed",ylab="distance")
Even though everything seems correct the terminal doesn't move to the next part
What environment are you using? I was able to execute the following code and produce the plot you want using both RStudio and R directly in the terminal.
library(MASS)
plot(cars, xlab="Distance", ylab="Speed")
If you're running straight from the terminal then you'll need to specify a window to pop up. The following question has an answer that outlines what to do depending on your operating system:
How to pop up the graphics window from Rscript?
So, for example, if you don't have your system configured to automatically open the plot window, and you're running on a mac, the following code will produce what you want directly from running R in the terminal:
library(MASS)
X11()
plot(cars, xlab="Distance", ylab="Speed")
I'm trying to iterate in parametric mode to plot several concentric arcs of circles with the parameter t ranging according to a function. I've tried, among others,
a=sqrt(2)
plot [-pi/2:pi/2] a*cos(t), a*sin(t)
do for [i=2:10] {
a=sqrt(2)/i
set trange [-1./2*acos(-(a**2)/2.):1./2*acos(-(a**2)/2.)]
replot a*cos(t), a*sin(t)
}
what I see is a plot of 10 identical overlapped arcs. I also replaced replot with plot and only the last arc is retained.
I know "that iteration does not work for plots in parametric mode" (ref. "plot for" in the manual), but this is using a do for construct. There must be a way to do this! How?
System: gnuplot Version 5.2 patchlevel 2, windows 10.
Today I developed my own solution, which is
a(i)=sqrt(2)/30*(31-i)
s(t, i)=t*(1./2*acos(-(a(i)**2)/2.))/(pi/2)
set trange [-pi/2:pi/2]
plot [-pi/2:pi/2] for [j=1:30] a(j)*cos(s(t,j)), a(j)*sin(s(t,j)) lw 2
Notice that in the meanwhile I made a little math adjustment from a=sqrt(2)/i to a(i)=sqrt(2)/30*(31-i).
Output:
The settings used to output that picture are
set term wxt size 800,800
set grid
set size ratio -1
set parametric
set xrange [-1.6:1.6]
set yrange [-1.6:1.6]
The rationale behind this is that in this way I set trange only once, and then with a variable substitution I map [0:pi/2] to [0:s(pi/2,i)].
You can use the for loop inside your plot statement. Try this:
set term png
set out "tmp.png"
unset key
set parametric
plot for [i=2:10] (sqrt(2)/i)*cos(t), (sqrt(2)/i)*sin(t)
exit
Output:
Update: the solution above won't take care of the trange requirement of the question. For that, one possible solution is to create a series of tables with proper ranges, and then loop through the files created for the plot. Something like the following:
set term png
set out "tmp.png"
unset key
set parametric
do for [i=2:10] {
a=sqrt(2)/i
set trange [-1./2*acos(-(a**2)/2.):1./2*acos(-(a**2)/2.)]
set table 'data'.i.'.txt'
plot a*cos(t), a*sin(t)
unset table
}
plot for [i=2:10] 'data'.i.'.txt' w l
exit
Output:
Hope this solution works! With a little help from this post.
You can often avoid parametric mode by using the + special filename in conjunction with a using statement:
plot for [i=2:10] [t=-1./2*acos(-((sqrt(2)/i)**2)/2.):1./2*acos(-((sqrt(2)/i)**2)/2.)] '+' using (sqrt(2)/i)*cos(t):(sqrt(2)/i)*sin(t) notitle with lines
I want to create figures that perfectly match the requirements of certain journals. They usually ask for a axis label between 6-8 points.
So far, I used the following commands within the png() command:
pointsize=1,width=8,height=6, units="cm", res=300
and within parameters par():
cex.axis=6,cex.lab=8, cex=1
My axis commands look like that:
axis(2,at=seq(0.7,1.1,0.1),labels=seq(0.7,1.1,0.1),
lwd=1.5,lwd.ticks=1.5,las=1,cex.axis=6)
The issue is the following:
When I create a smaller picture (like 4x6 cm) this set of commands works perfectly fine, e.g. I obtain a picture with an axis label in 6 points.
However, when I create bigger pictures like (16x9 cm) the axis labels are printed smaller than 6 points, which is super annoying. I do not have a clue what's happening.
Any Ideas? Thanks a lot
I have some problems of using gnuplot. I just begin with it.
(1)What is the command for keeping the previous plot when I plot new data? Do I have to plot the old data and the new data at the same time?
(2)What is the command for open a new window while keep the old ones? Do I have to set the window's id by using, e.g.,
set terminal wxt 3
, before each plot?
Can anyone give me some help or some good references?
Usually, to plot several data set you would use
plot 'data1.dat', 'data2.dat'
You could also use replot to add one of the data sets later
plot 'data1.dat'
...
replot 'data2.dat'
To open a new window, you must use the window's id like with set terminal wxt 2. The old windows stay open, but you cannot interact with them anymore (zooming, scrolling etc.). See also the discussion to the quesiton Two interactive windows in Gnuplot with wxt terminal.
You already wrote the answers of your questions.
1.: You can use the replot command:
plot sin(x)
replot cos(x)
but this just expands to
plot sin(x), cos(x)
So, it replots all data and does not just add the cos(x).
2.: Yes, you can also switch between the windows to update the plots. But note that settings like ranges and labels are not stored per window / plot, but globally. If they are different for different plots, you have to change them every time.
You may also have a look at "set multiplot" to put several plots on one window / picture. But it is not so nice for interactive plotting, as you will notice.
Also, output terminals supporting multiple pages like pdfcairo will add a new page for each plot.
I have a laptop with low screen resolution. As a consequence, when I give a plot command in R the Quartz plot object runs off the screen.
Is it possible to change set some option -- preferably in my .Rprofile -- that will reduce the size of the default plot output when using interactive R?
?quartz
quartz.options(width=4, height=4)
(The default values are 7 and 7 which can eaisly be obtained by typing just:
quartz.options()[c("width", "height")] # .)