Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to plot graph in julia while executing loops?

Tags:

plot

julia

Let us consider the following scenario .

     for x in range (1,100)
         for y in range (2,500)
                 #plot(f(x),g(y))
         end
     end

where f(x) and g(y) are some user defined functions.

The output must be the desired points on plane.

Is there any way in julia to do like what I need ?

In general I can do like this

     for x in range (1,100)
         for y in range (2,500)
                 push!(l,f(x))
                 push!(m,g(y))
         end
     end

and then plotting from the two lists l,m as x,y axes respectively.

But now I want to plot points while executing loop.

like image 782
hanugm Avatar asked Jun 11 '15 19:06

hanugm


People also ask

How do you show a plot in Julia?

A Plot is only displayed when returned (a semicolon will suppress the return), or if explicitly displayed with display(plt) , gui() , or by adding show = true to your plot command.

Why is plotting in Julia so slow?

It is caused by Julia compiling the needed functions on the fly (precompilation only does half of all the compile work). If you search for “time to first plot” you will find a large amount of reading material…

What does plot do in Julia?

3.2. Plots plots functions by creating a large number of paired points ( x , f ( x ) ) ; it then plots these points; and, finally, connects the points with line segments.


2 Answers

This is mostly supported in Plots... see https://github.com/tbreloff/Plots.jl/issues/30 for a little more information and some example usage.

like image 126
Tom Breloff Avatar answered Sep 29 '22 06:09

Tom Breloff


use the display function:

for x in 1:100
          p = plot(f(x),g(y))
          display(p)
          sleep(1)
 end

(inspired by Andreas Peter on the Julia slack #helpdesk channel)

like image 39
Vass Avatar answered Sep 29 '22 06:09

Vass