Plotting remotely using mayavi and python - python

I have a massive file I need to parse and render on a remote machine, I already have scripts written using mayavi to do exactly this. What I'd like to do is save the image as a png and then copy the image over and view it locally. This is pretty simple to do with matplotlib by setting the backend to 'Agg', however I'm having some serious problems doing this with mayavi. I've followed the guide here
http://docs.enthought.com/mayavi/mayavi/tips.html
but the problem is that importing mlab alone requires access to the xdisplay, so I can't even turn on the virtual window as suggested.
To reproduce this, access a machine through ssh and run a simple python script like:
#!/usr/bin/python
from mayavi import mlab
and it will error out with the standard;
Unable to access the X Display, is $DISPLAY set properly?
If anyone has a fix for this, or an alternative route to rendering a 3D image remotely I'd appreciate it. The 3D rendering provided by matplotlib is insufficient for what I need so any suggestions for working alternatives to mayavi would be appreciated as well.

If you are on a *nix platform running an X server, use the solution in the documentation under rendering using the virtual framebuffer as dpinte commented above. I have used this method successfully before to run mayavi scripts headlessly.
The basic idea is to start a virtual X server such as Xvfb, and then invoke mayavi in the display context of the virtual X server (and yes this explanation is not quite right, but it will suffice).

Related

Interactive plot with Matplotlib in web browser for anyone to run

I have made a script in Python to visualize the intersection of a line between two points and 2 circles. The code runs really well but I'd like to also be able to share this with people who don't have to install python or library to run it. Like in a web browser.
I have found a library called mpld3 that could do the job but unfortunately the sliders that I used don't work at all, and they are glitched for some reason. The glitch in question
So I was wondering first if mpld3 was a good solution and if so, how can I solve my problem? I really can't find anything online related to my issue so it's really bothering me. Thanks in advance.

Remote interpreter and local plot in PyCharm?

I'm using PyCharm with a remote interpreter. My code is showing a scatter figure using matplotlib. I can see the figure normally and interact with (zoom and rotate), but the interaction is too slow. I think this is because it's done through the SSH X-server.
My question is how to manually make the figure interactions graphically (using mouse, like zooming, panning, rotation, ...) execute faster? I think this should be via allowing the figure interactions to happen on local machine (machine running PyCharm), not the remote server.
One workaround is to save a .fig file, then copy it to my local machine, then load it. But I don't prefer this workaround.
Interacting with visualisations on separate windows is slow, not just on PyCharm but any IDE that you specify visualisations to be loaded separately. This is because they are loaded on either tkinter or any of the available modules like Qt5 and if you're on a mac, you can also use the inbuilt OSX rendering. Especially if your dataset is large then interaction becomes slower. It just seems that visualisations in Python are not exactly that optimised as you witness on Tableau or even Orange/Glue.
That's why I personally prefer visualising data inline through the IPython console (for that I use Spyder). You cannot interact with plots though, but the purpose suffices.

iGraph won't plot from function - Python

So I'm setting up iGraph, and I'm having issues with the plot showing up.
The simple code is this
import iGraph
igraph.plot(igraph.Graph.Tree(127,2), layout='tree')
this will plot when i type it directly into python compiler (i'm using canopy)
But when trying to run it through the intpreter it does not display?
I assume this is a very basic issue but cannot seem to understand why it is occurring.
The Canopy GUI's default graphical backend is Qt. Most likely igraph uses a different graphical backend which conflicts with Qt. Try disabling Canopy's default Pylab mode in the Preferences dialog (Python tab). For more information, see https://support.enthought.com/hc/en-us/articles/204469880

Distributing an interactive matplotlib plot

I have a Python script that generates an interactive matplotlib plot with several sliders and radio buttons using the matplotlib.widgets submodule. I'd like to let others play with the resulting plot without having to install python, scipy, numpy, and matplotlib.
I first tried converting my python script to a stand-alone executable that I could distribute. This turned out to be a nightmare - every package I tried (pyinstaller, py2exe, cx_Freeze) failed for one reason or another. The main issue I had was with integrating various scipy and matplotlib libraries, and I'm now very pessimistic about successfully "freezing" my interactive plot.
My next idea was to see if I could get some interactivity through a web browser. Using an IPython notebook with the third-party package JSAnimation initially seemed very promising (http://nbviewer.ipython.org/github/jakevdp/JSAnimation/blob/master/animation_example.ipynb), but it seems that the package only supports the matplotlib "animate" function. This doesn't quite fit the bill for what I'd like to do, as I have multiple sliders which 1) doesn't seem to be supported by this package, and 2) even if supported, would likely result in too many static figures to pre-render effectively, since any such arrangement would require snapshots for every possible combination of the three variables.
Any ideas for how to get this interactive matplotlib plot to others without requiring them to install Python?

wxPython GUI: migrating gnuplot to matplotlib

I currently have a GUI built in wxPython with several sections, one of which displays a .png image of a plot:
self.plot = wx.BitmapButton(self.pane_system, -1, wx.Bitmap("/home/myname/projects/newton/plot/src/graph.png", wx.BITMAP_TYPE_ANY))
In another part of the GUI, there is a place where I can edit parameters. The current setup is that When I change the parameters and press enter, the code tells Gnuplot to re-plot and save the new plot to the graph.png file, then update the GUI to show the updated image.
I have several general questions:
I want to migrate gnuplot to matplotlib for the following reason: If I use gnuplot, the machine that is running the executable must have gnuplot installed on their machine. On the other hand, matplotlib is a python module, so I don't have to worry about installing graphical packages on the other machines. Is this assumption correct?
How can I modify my wxPython GUI window to show the matplotlib plot? I found tutorials several telling me how to create a new panel with a matplotlib plot, but I would like to simply have it appear where the old plot was. I think I can make matplotlib save the plot to an image file just as I did in gnuplot. Is it generally a good idea to save the plot as an image and update the GUI, or are there other (faster) best practices for updating plots? One drawback of using image files (as in the above code) is that they do not resize when I resize the GUI window.
If I package this as an executable, will I have to install wxPython/Python on a Windows machine to make the executable run?
Taking your questions in order:
1.) Yes matplotlib is a contained python module. It does have external dependancies but in Windows these dependencies are packaged with the matplotlib install. Do you need to worry about these when you install on other machines? That depends on how you are going to install. Are you packing to an exe? Having the end users install Python and matplotlib? As an example you can package matplotlib into your exe with py2exe, see here. Of course you'll have to customize those scripts for your backend, wx.
2.) You are seeing the panels with plots because matplotlib provides the FigureCanvasWxAgg, which is a wxWidget derived from wxPanel that plays nice with matplotlib. The advantages of using it are that you can set handlers for stuff like resize and painting.
Your wxBitMapButton, though is looking for a wxBitmap for the image. You might be able to give it a file handle (cStringIO.StringIO) to a matplotlib plot and eliminate the need to write a file to disk. You also could probably hook it's resize event and get matplotlib to redraw the figure to the appropriate size. You aren't going to have the amount of flexibility as using the FigureCanvasWxAgg. I can't research any of this, though, as it seems the wxPython web-site is down.
3.) You can package wxPython into executable. How depends on what packager you are using. I've done this with py2exe many times.

Categories