I am running a program which uses a plotting subroutine for gnuplot. I am running a script and am supposed to view the resultant plot in real time.
Inside the do loop, the plotting command would come up say 100 times. Because of this I am obtaining 100 seperate gnuplot windows containing the plot.
The program is like
do i=1,100
...
...
call plota1(x,y)
end do
Is there any way such that I do not get such 100 plots,only one, and say, when the (i+1)th plot comes, it will come in the same gnuplot window replacing the ith plot?
The plotting subroutine used is as follows.
subroutine plota1(x,y)
real*8::x(:),y(:)
integer l,u,i
l=lbound(x(:),dim=1)
u=ubound(x(:),dim=1)
open(1,file="p.dat")
open(2,file="p.plt")
do i=l,u
write(1,*) x(i),y(i)
end do
write(2,*) "p 'p.dat' u 1:2 w l"
call execute_command_line('gnuplot -p p.plt')
close(1,status='delete')
close(2,status='delete')
end subroutine plota1
The plotting command comes from the line "write(2,*) "p 'p.dat' u 1:2 w l"".
What should I add there to get the desired output? If there is no way, suggestions for using some other software will also be helpful.
The subroutine you show is doing two things. It creates a new data file, then it creates a new gnuplot instance to plot the data in that file. That's not what you want. You want a single-purpose subroutine to fill a data file with the new data, then a separate subroutine (or direct call from the main program) to tell an already existing instance of gnuplot to plot the data from that new file. I.e. you need to separate the steps of opening a gnuplot instance and then later sending commands to it. Since you do not say what library you are using, people cannot advise you whether it contains appropriate routines or not.
Related
I want to visualize multiple figures in Julia to compare them, and I want to open two separate figures.
Let's say I want to compare two sets of random numbers in two separate windows.
In MATLAB, this can be easily done with
figure(1)
scatter(1:10, rand(10,1))
figure(2)
scatter(1:10, rand(10,1))
This answer describes how to place the plots next to each other in Julia. For example, the following code does that.
using Plots
p1 = plot(LinRange(1,10,10),rand(10))
p2 = plot(LinRange(1,10,10),rand(10))
plot(p1,p2)
Is there any way to open the plots simultaneously in two different windows in Julia, like MATLAB?
If the Plots package cannot do that, is there another package that implements this feature?
A workaround can be using the PythonPlot backend. It's a drop in replacement for pyplot. First, install this backend using ] add PythonPlot. Then continue:
julia> using Plots
julia> pythonplot()
Plots.PythonPlotBackend()
julia> p1 = plot(LinRange(1,10,10),rand(10))
julia> p2 = plot(LinRange(1,10,10),rand(10), reuse=false)
The output would be:
I have a matlab code that I would like to run 3 inputs through that I have in R (delta_x, cutoff_1, cutoff_2).
First I would like to know how to save these in order to run them through the matlab code. delta_x is an r dataframe with around 1000 lines of data in a single column. Cutoff 1 and 2 are both just integers
The code is much longer than that shown below so it would take far too long to convert into R and I am on a tight schedule and not very familiar with matlab.
Essentially, what I would like to do is run my 3 inputs that I have in r through the matlab code that I have been provided with. Is anyone aware of how I can do this? I have read something about matlabr package?? but not been able to figure it out.
Matlab code looks like the following for reference:
function [start_end]=plume_finder(delta_x,cutoff_1,cutoff_2)
[pks,pksloc]=findpeaks(delta_x);% find the peaks
valley=find(islocalmin(delta_x)==1);% find the valleys
list_va=delta_x(valley);%find the values at the valley
%There is two possibliltes, the valley presents first or the peak present
%first. So we have to use 'shift' to make adjustment for this.
if valley(1)>pksloc(1)
shift=0;
else
shift=1;
end
upperlim=min(length(pks),length(valley));% Find where to stop
%pksloc(:,2:end), indicating the whether this peak point could meet the
%requirements(2:whether the peak value greater than the cut-off, 3:whether
%the peak value has significant difference from valley point on its left,
%4:whether the peak value has significant difference from valley point on
%its right--> 1 stands for yes, and 0 stands for no)
for i=1:upperlim
if pks(i)<cutoff_1
pksloc(i,2)=0;
else
pksloc(i,2)=1;
end
end
for i=2:upperlim
if (pks(i)-list_va(i-1+shift))<=cutoff_2
pksloc(i,3)=0;
else
pksloc(i,3)=1;
end
end
In MATLAB, write a matlab script that can load ascii .csv files, process data and save results to new ascii .csv files.
In R, save the variables to ascii .csv files.
In R, invoke matlab script in batch mode through system() and wait for the generation of new processed files.
In R, load the processed data file, and do whatever is waiting for.
P.S.1. csv files are pretty straightforward but lose precision, HDF5 or SQLite formats can be used instead.
P.S.2. The whole thing can be turned around that some R script is invoked within matlab through file system and system calls. Or call both R and MATLAB from bash or python or something else.
P.S.3 It's also possible to pass data through a local network socket connection, I will leave the details for now.
I use R and MATLAB from the command line and edit files with external editors. In MATLAB, the command workspace opens a graphical window with a list of all variables and the current values. If I double click on a complex object, like a matrix, MATLAB automatically opens another window with a table containing the values.
Is there any similar way to do so in R?
In this link, in the end of the first "box", it is listed the command browse.workspace, which seems what I am looking for. Unfortunately I cannot invoke it.
I tried with commands which prints output in the terminal (like str(as.list(.GlobalEnv))) but I do not like the result. When I have got a lot of variables it is a big mess.
I'm trying to write a function that plots a ggplot facet_wrap plot over multiple pages. It's just a hack, as this feature seems to be on the ggplot2 feature to-do list. I do some small calculations to find the number of pages I'm going to need, the number of rows of my data.frame that I need per page etc. I'm pretty confident this all works.
pdf(filename)
for (i in seq(num_pages)){
slice = seq(((i-1)*num_rows)+1,(i*num_rows))
slice = slice[!(slice > nrow(df.merged))]
df.segment=df.merged[slice,]
p <- ggplot(df.segment, aes(y=mean,x=phenotype))
p <- p + geom_bar(stat="identity",fill="white",colour="black")
p + facet_wrap("ID",scales="free_y",ncol=n_facets,nrow=n_facets)
}
dev.off()
My problem is that, by wrapping it all up in a for loop like this, in between the pdf() and dev.off() functions, is that the for loop doesn't seem to wait for ggplot to do its thing, and blazes through its loop very quickly and outputs an invalid PDF.
If I set i = 1, start the pdf(), run the above code inside the for loop, then set i=2, then run the code, and so on until I get bored (i=3) then turn off the device the resulting PDF is brilliant.
Is there a way I can get the for loop to wait for the final line to finish plotting before moving onto the next iteration?
I think the problem is that you need print() around your last line (p+ ...) to get it to actually print to the device inside the for loop . . .
Exactly. Page 39 of the ggplot2 book tells us that when you create ggplot2 objects, you can "Render it on screen, with print(). This happens automatically when running interactively, but inside a loop or function, you'll need to print() it yourself".
thank you kindly for your time.
I'm merely trying to plot a simple time series data set, but am running into a number of basic issues (one of which I'll ask here). For example, I have a notepad file that starts with:
"x"
"1",2.731
"2",2.562
"3",2.632
"4",2.495
"5",1.978
...and so on...
So R reads it just fine, e.g. myfile=read.table("F:/Documents/myfile.txt",sep=""). However, the values seem to change under a conversion using R's ts function, i.e.
myfile = ts(myfile,start=1,end=120,frequency=1)
plot(myfile, type="o",pch=22,lty=1,pty=2,xlab="Month",ylab="Values",main="My File")
So when plotted, the first value starts at 20+ for some reason, as opposed to 2+. Furthermore, R assumes that the y-axis goes from 1 to 120 (mirroring the x-axis), which is not the right scale (i.e. 0 through 10). In another data set that I did (using integers), it was shifted upward by 1. In any event, I believe the issue is probably about how to properly identifying the y-axis.
Any ideas on how to tackle this? Thanks!