Plot paraview data format file in mayavi - plot

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

Related

Using plot within a script in julia

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.

ipywidget interactive plot in Html presentations ipython notebook

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."

Using code from ipython in Rstudio

I am trying to CLV in R using data from Big Query.
I have found an article describing how to do it, but the guide codes in iPython instead of, which I not familiar with.
(The guide I want to use: https://github.com/googleanalytics/bigquery-export-ipython-notebooks/blob/master/notebooks/customer-base-analysis.ipynb)
My question is:
- Why would you run R code in iPython and not in Rstudio?
- What code do I have to change in order to run the same analysis in Rstudio instead?

save R image plot via org.rosuda.jri.rengine

I use org.rosuda.jri lib to run an R script that implements the ordinary kirging algorithm via java. I use ubuntu 13.04 and the version 1.7-3 of REngine While all the results are perfectly produced BUT i can not create the plots and store them.
while the following lines are perfectly executed in R console
png('/home/panisis/Desktop/plots/tralala.png');
spplot(df);
dev.off();
These ones are ignored
re.eval("png('/home/panisis/Desktop/plots/tralala.png');");
re.eval("spplot(df);");
re.eval("dev.off();");
What i am missing???
Thanks for the dedicated time. :-)
i just found the answer myself. i put it here for next users. i had to assign the plot to a temporary variable (like temp <- spplot()) and then use print(temp) to save it as png file for example temp <- spplot() png(filename="pathToFile") print(temp) dev.off()

plotting data in R from matlab

I was wondering if it is possible to work between matlab and R to plot some data. I have a script in matlab which generates a text file. From this I was wondering if it was possible to open R from within matlab and plot the data from this text file and then return to matlab.
For example, if I save a text file called test.txt, in the path 'E:\', and then define the path of R which in my case will be:
pathR = 'C:\Program Files\R\R-2.14.1\bin\R';
Is it possible to run a script already written in R saved under test1.R (saved in the same directory as test.txt) in R from matlab?
If you're working with Windows (from the path it looks like you are), you can use the MATLAB R-link from the File Exchange to pass data from Matlab to R, execute commands there, and retrieve output.
I don't use R so this is not something I have done but I see no reason why you shouldn't be able to use the system function to call R from a Matlab session. Look in the product documentation under the section Run External Commands, Scripts, and Programs for this and related approaches.
There are some platform-specific peculiarities to be aware of and you may have to wrestle a little with what is returned (though since you are planning to have R create a plot which is likely to be a side-effect rather than what is returned you may not). As ever this is covered quite well in the product's documentation
After using R(D)COM and Matlab R-link for a while, I do not recommend it. The COM interface has trouble parsing many commands and it is difficult to debug the code. I recommend using a system command from Matlab as described in the R Wiki. This also avoids having to install RAndFriends.

Resources