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:
Related
I'm working through a book, The R Student Companion, and in the first chapter I've run across a problem. I'm trying to plot a graph using R but the "points" statement isn't plotting my line onto the graph.
Here is what I've got going on. I'm defining some list variables and plotting them as so.
moose.density=c(.17,.23,.23,.26,.37,.41,.66,.80,1.11,1.30,1.37,1.41,1.73,2.49)
kill.rate=c(.37,.47,1.9,2.04,1.12,1.74,2.78,1.85,1.88,1.96,1.8,2.44,2.81,3.75)
plot(moose.density,kill.rate,type="p")
As a result, I get this graph:
.
Then I add these values and use the "points" statement to plot the line.
m=2.5*(0:100)/100
a=3.37
b=0.47
k=b*m/(a+m)
points(m,k,type="p")
This is the expected graph from the book, but nothing changes on mine. Am I doing something wrong? Is the points statement depreciated? I followed the book line-by-line.
I thought it might have something to do with my R installation on Manjaro, but tried it on a Windows machine and got the same result.
From the comments discussion, it appears that the code in this book contains several errors on certain pages, but not others.
The most relevant error is that:
k = b * m / (a + m)
generates values that are too small to appear on the plot. It should be:
k = a * m / (b + m)
It appears that someone has already solved one part of the problem. Next, you should change points(m,k,type="p") to lines(m, k).
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.
I am trying to plot a function in Julia, but keep getting errors. I don't understand what is wrong. The input and output of $\varphi$ is a scalar. I've used x=1530:1545 and still get an error-- can anyone enlighten me? I am very confused.
I am using Julia 0.7.
EDIT:
I got it to work with a slight modification--I changed
x = 1530:1545
added the following two lines
y = t.(x)
plot(x,y)
Why did I have to do this though?
This feature is currently not available in PyPlots.jl, if you would like to have it in the future, your best bet is to file an issue.
However, you can get that functionality via Plots.jl and using PyPlot as a backend.
It would look like this (I'll take a simpler function):
using Plots
pyplot()
start_point = 0
end_point = 10
plot_range = start_point:end_point
plot(sqrt,plot_range) # if you want the function exactly at 0,1,2,3...
plot(plot_range,sqrt) # works the same
plot(sqrt,start_point,end_point) # automatically chooses the interior points
I'm learning Shiny and I am trying to write an app to explore Simpson's paradox graphically. I built the plot in R first, with customizable options set a the beginning. The plot shows data that are positively correlated but that can be factored into groups which are negatively correlated. The options at the beginning include how many groups to have, how they're spaced, whether to show the grouped/ungrouped regression lines, etc. See the working simpson.R script here.
The intent of the app is to get the user to play with these options to make the groupings more or less obvious and to highlight (or not) the negative correlations.
The complete code for my app files is on github. I don't have sufficient reputation to post more than two links, so please find ui.R and server.R there in the repo.
The error I can't seem to get past is non-numeric argument to binary operator apparently somewhere in this line:
anchors_x <- rep(seq(2, 2 + (input$number_of_groups - 1) * input$separation,
by = input$separation)
and also
p <- ggplot(data = dfserver(), aes(x, y))
Specific question:
Why isn't R treating these variables as numeric?
More generally:
Was it smart of me to build the plot in a plain R script first? Or would a more typical workflow be just to build the thing in Shiny from the beginning? If so, how does one debug/build R inside of Shiny if one can't get into the environment to poke around at the objects? Or is there a way I don't know to access objects that live inside ui.R and server.R?
input$number_of_groups and friends is a string.
Try
ng = as.integer(input$number_of_groups)
sep = as.integer(input$separation)
ppg = as.integer(input$points_per_group)
anchors_x <- rep(seq(2, 2 + (ng - 1) * sep, by = sep), ppg)
and similar further below
I would like to provide more than one graph as input to the equiv.clust function in the sna package. For example
library(ergm)
library(sna)
data(florentine)
flobusiness # first relation
flomarriage # second relation
eq<-equiv.clust(flobusiness)
b<-blockmodel(flobusiness,eq,h=10)
plot(b)
So far so good. I get the output I expect. However, how do I include both relations in the equiv.clust and blockmodel commands?
According to the Usage in documentation
equiv.clust(dat, g=NULL, equiv.dist=NULL, equiv.fun="sedist",
method="hamming", mode="digraph", diag=FALSE,
cluster.method="complete", glabels=NULL, plabels=NULL, ...)
where
dat one or more graphs.
Specifically, I am requesting to know how to provide two or more graphs in as the dat part of the argument. Thanks a ton
try entering the graphs as a list, as in:
equiv.clust(list(flobusiness,flomarriage))
not sure if that will work but in general I think you need to use lists to analyze multiple graphs. though in this case, it depends on whether you want two separate blockmodels in which case you could just loop or use
lapply(equiv.clust, list(flobusiness,flomarriage))
and then a slightly more complicated statement for the block model, or whether you want a blockmodel of the combined network in which case you could just add them together