I'm plotting F# functions in a Jupyter Notebook on a .NET Interactive Kernel like this:
Plotting F# function in Jupyter
I want to make this graph interactive so variables (and therefore the line of the graph) can be manipulated live. Is it possible to add a slider UI control with F#, like it can be done in Python with ipywidgets?
Related
I am following the schelling.jl tutorial from the Agents.jl package (https://juliadynamics.github.io/Agents.jl/stable/examples/schelling/). Towards the end of the tutorial they create an interactive application. But when I run the script (include("schelling.jl")), I end up with figure instead of an interactive app (cannot click on the run, reset buttons since it appears to be a figure). Any ideas how I get it as an interactive app?
using InteractiveDynamics
figure, adf, mdf = abm_data_exploration(model, agent_step!, dummystep, parange; ac=groupcolor, am=groupmarker, as = 10, adata, alabels)
Note I am using vscode IDE
You need to specify the proper plotting backend, CairoMakie can output static vector graphics but it can't open interactive windows. You can use GLMakie or WGLMakie instead.
Package
Description
GLMakie.jl
GPU-powered, interactive 2D and 3D plotting in standalone GLFW.jl windows.
CairoMakie.jl
Cairo.jl based, non-interactive 2D backend for publication-quality vector graphics.
WGLMakie.jl
WebGL-based interactive 2D and 3D plotting that runs within browsers.
#see Mackie's Backends & Output
I've been prototyping some julia code in a Jupyter notebook, but it's outgrown the notebook format and I want to put it in a script in order to organise it properly. However, I can't work out how to get Plots to work in a script, and can't find any documentation about it.
Here's a minimal not-working example:
using Plots
gr()
display(plot([1,3,2]))
println("here")
This code takes 20-30 seconds to import Plots, then opens a window but immediately closes it again, prints "here", and exits. I can't use ctrl-C while the import process is happening.
So, I have three questions:
How do I prevent the plot window from closing as soon as it opens? What I want is for the script to block or (ideally) enter an event loop until the window is closed, and terminate after that.
Can the extremely long import time be reduced somehow?
Does any documentation exist for using Plots outside of a Jupyter environment?
If it makes a difference, I'm using julia 1.1.1 on a Mac.
The most natural way to achieve the workflow you're looking for in the first bullet is to use Juno or VS Code. Suppose in your working directory you have the following code in a file script.jl:
using Plots
gr()
display(plot([1,3,2]))
hello = "world"
println("here")
Now fire up Juno or VS Code and launch the integrated Julia REPL. From the Julia REPL, you can use include to source your script:
julia> include("script.jl")
Plot{Plots.GRBackend() n=1}
here
Now your script has been completely run and the plot is available for viewing in the plot pane (this is true for both Juno and VS Code). Now you can continue to include other files in the REPL or run other code interactively. Note that variables defined in script.jl are available for use:
julia> hello
"world"
EDIT:
If you run a script using the -i option (for interactive), the plot GUI will stay open and a REPL will launch after the script is done running:
$ julia -i script.jl
The various options to the Julia executable can be found here, or can be found by typing $ julia --help in a terminal.
The import time can be eliminated by compiling the Plots.jl package ahead of time and baking it into your julia executable using the PackageCompiler.jl package. Here is a link to the package website
https://julialang.github.io/PackageCompiler.jl/dev/
See the tutorial on how to do this, the first tutorial is about compiling a syntax highlighting package. That one replaces your default 'sysimage'. The second tutorial is about creating a loadable 'sysimage' where Plots.jl is compiled, and starting Julia with this 'sysimage' so it doesn't have to complie Plots.jl again.
However I coudln't get the second 'loadable sysimage' working so I used the first tutorials way even for Plots.jl.
After this change, using Plots and plot() are basically instant.
I would like to use the interactive function from ipywidget in an ipython notebook to make a presentation in notebook.
I have stored my data in a pickle file and what I want is to change the parameters interactively so that I can see my plot.
My code is like this.
def spin(model, power):
with open(path_cluster1+'SSHFS/Model'+str(model)+'/'+str(power)+'/spinpython2.pickle','rb') as f:
spin = pickle.load(f)
plt.plot(spin)
plt.title('Power'+str(power*0.1))
interactive(spin, model=(1,4,1), power=(70,101,1))
My collaborators are unfamiliar with python so in principle I would like to make the life easier for them to see my data just by changing a parameter in a html page. Maybe I have to save all the data in a pickle file but the question is if this can work in a html without running python.
Is something like this possible?
Have a look at https://www.nbinteract.com/. To quote from the website "nbinteract is a Python package that provides a command-line tool to generate interactive web pages from Jupyter notebooks."
I have produced a plot using the ggvis package in R. The plot is interactive which can be changed by moving around the slider. However when I save it, it is just a picture of current status without sliders.
I have seen people posting these interactive plots on the website, so I think there should be a way to save it first. How can I do this?
From the Rstudio page for ggvis:
Note: If you’re viewing the HTML version of this document generated with knitr, the examples will have their interactive features disabled. You’ll need to run the code in R to see and use the interactive controls.
From this and the whole page I gather that sharing the interactive graphics can be done using Shiny Apps and/or R Markdown documents. To deploy either of those to people who do not have R installed you need to a) use Shiny Apps IO; or b) install Shiny Server, which has a free version with very basic administration capabilities, and a paid version for confidential information in corporate environment (which I'm only mentioning in case you are not allowed to share your data).
Either way, read through the Shiny Tutorial, the
R Markdown Tutorial, and the combination.
I am solving PDE numerically using FEniCS with its python interface. I am using the ipython notebook to code in python and I want to plot the result using mayavi. I don't want to use paraview to plot it.
The code which I used to save the result in the file is
file=File('grad_shafranov.pvd')
file<<w