Current conditions:
C code being rewritten to do almost the same type of simulation every time (learning behavior in mice)
Matlab code being written for every simulation to plot results (2D, potentially 3D graphs)
Here are my goals:
Design GUI (wxPython) that allows me to build a dynamic simulator
GUI also displays results of simulation via OpenGL (or perhaps Matplotlib)
Use a C wrapper (CFFI) to run the simulation and send the results (averages) to OpenGL or Matplotlib
Question:
In order to have this software run as efficiently as possible, it makes sense to me that CFFI should be used to run the simulation...what I'm not sure about is if it would be better to have that FFI instance (or a separate one?) use an OpenGL C binding to do all the graphics stuff and pass the resulting graphs up to the Python layer to display in the GUI, or have CFFI send the averages of the simulations (the data that gets plotted) to variables in the Python level and use PyOpenGL or Matplotlib to plot graphs.
It would help to know what the turnaround time for the simulation runs is and how fast you want to display and update graphs. More or less realtime, tens of milliseconds for each? Seconds? Minutes?
If you want to draw graphs, I'd recommend Matplotlib rather than OpenGL. Even hacking the Matplotlib code yourself to make it do exactly what you want will probably still be easier than doing stuff in OpenGL. And Matplotlib also has "XKCD" style graphs :-)
PyOpenGL works fine with wxPython. Most of the grunt work in modern 3D is done by the GPU so it probably won't be worth doing 3D graphics in C rather than Python if you decide to go that route.
Hope this helps.
Related
I am working in a project where 3D visualizations are important to see what is happening during the setup stage and perhaps for visual validation by making a short videos of what is happening.
The problem that I have is that 3D visualizations in Python are too sophisticated, and complicated to learn for what I need. I find that Mathematica is the perfect kind of software...but it is not portable and is very expensive.
Question
Is there any Python package similar to Mathematica?
Clarification
I don't want a "plotting" program, since plotting is not what I am looking for. I want to generate simple geometric shapes like spheres and cubes that can move around, this is more than enough. Give some coordinates, perhaps a rotation, and the program just shows the desired image(s) to export as a .png or make a quick video; as in Mathematica.
Packages like Pygame, Panda3D, Pyglet, etc., look too complicated and an overkill for what I need, as well as software like Blender, etc. Jupyter notebooks are similar, but they don't have the 3D graphics capabilities. I found a Python module named Fresnel, but it looks too sophisticated for what I need.
I have read several answers to this question here in Stack Overflow, but they seem outdated and not really what I am looking for.
Further Clarification
To draw spheres in Mathematica you do:
coordinates = Flatten[Table[Table[Table[ {i,j,k}, {k,1,10}], {j,1,10}], {i,1,10}],1]
spheres= Flatten[Table[Graphics3D[{Sphere[coordinates[[i]],0.5]}],{i,1,Length[coordinates]}]]
Show[{spheres}]
This is a simple quick and easy way of displaying a group of spheres. To use any program in Python to do the same, it seems like you must be an expert in 3D graphics to do this simple thing.
Programs that have capabilities of using Python scripts, like Blender, make it difficult to use the interface in a straight forward way (try doing the same in Blender, it will take a while just to learn the basics!).
I know several other user-friendly plotting libraries than matplotlib, but not a lot provide an interactive view. There is of course the well known vtk but it's not for end-user
plotly
For usage in a notebook, like jupyter and mathematica, you probably would go for plotly It's using a browser-based interface with plots very similar to mathematica
pymadcad
If you need a more offline version and what you are looking for is some view you can rotate/zoom/pan to look on your geometry by different sides, you can take a look at pymadcad
It even works with touchscreens.
It is not centered on 3D visualization, so it's a bit overkill to use it only for it, but for 3D curves, 3D surfaces, spheres and cubes as you said, it can do the job
simple plots with pymadcad:
from madcad import *
from madcad.rendering import Displayable
from madcad.displays import GridDisplay
# create a wire from custom points
s = 100
mycurve = Wire([ vec3(sin(t/s), cos(t/s), 0.1*t/s)
for t in range(int(s*6*pi)) ])
# create a sphere
mysphere = uvsphere(vec3(0), 0.5)
# display in a separated window
show([
mycurve, # displaying the curve
mysphere, # displaying the sphere
Displayable(GridDisplay, vec3(0)), # this is to have a 2D grid centered on origin
])
result:
(The window is dark because so is my system theme, but likely it will adapt to yours)
Matlab and Mathematica both have features that allow the user to manipulate the contents of a plot using, say, a slider. For example, if you have a set of 3D data, it is easy to make a small program that lets you view 2D slices of a set of 3D data where the user can slide a slider to move through which slice is displayed. Is there anything in python that allows for this sort of capability without tons of effort? For example, is it possible to do such a thing in matplotlib, or something similar? I
Thanks.
My first thought would be Mayavi, which is great for data visualization, especially in 3D. It relies on VTK. It is included in the Enthought flavoured version of Python, together with Chaco for 2D plotting. To get an idea, look at Travis Vaught's nice screencast in Multidimensional Data Visualization in Python - Mixing Chaco and Mayavi.
It also possible to embed basic interactive functionalities (like slider) to Matplotlib, see matplotlib.widgets and the widget examples.
Finally, you can use rpy (or better, rpy2) and benefit from the R interface.
Have you looked at Vtk? http://www.vtk.org/ One of their demos does exactly what you're asking.
In principle, you can do it by help of MathGL. This is cross-platform GPL library for plotting.
For each mouse clicks you can find the x,y,z position in plot or clicked object and adjust (replot) some other information correspondingly. However you should handle mouse clicks by yourself (for example, using PyQt).
Another option is to use python within the SAGE computation interface/environment, which has the #interact command (see here for specific help on this command)
Is it possible to create a ui using traits from python to make an interface for a cellular automata simulation?
Of course, you can do anything with Traits that can with Python!
Seriously though, I presume your question is really about generating a GUI in which to display the CA. In that case I can recommend Mayavi which is based on Traits. It has a surf function which plots an array of regularly-spaced data as a 3D surface. There are docs on animating the data which shows how to change the underlying surface data for very fast rendering, which I have used and works well. I have a 3D numpy array shape=(x,y,time) and then for each step I pass a slice to surface objects data object:
surf.mlab_source.scalars = array[:,:,timepoint_index]
Alternatively you could use Matplotlib's imshow for a 2D plot of the same data. There is a very good tutorial on embedding matplotlib in traits.
One issue with using these large libraries (which themselves have many, many dependencies) is being able to distribute your application along with the libraries. I have successfully frozen a Mayavi/matplotlib/traits app on Mac using py2app and Windows using py2exe, starting from the Enthought Python Distribution, but it wasn't easy. However, if you just need it to work on your computer and generate results then both of these approaches will save you time over writing a graphics system for your cellular automata.
Having said all that I also hear good things about GarlicSim (as cool-RR mentioned), which would seem to be custom-made for your purpose.
Can't post links because this is my first post, I will add them later.
I am trying to create a GUI interface in VB to track... oh, nevermind.
Basically, I want to create a GUI in python to display data, but I am finding that mathplotlib is not suiting my needs. I would like to be able to highlight certain datapoints, have more freedom in the text drawn to the screen, have animations on data movement, and have dropdown menus for data points. From what I have seen, I do not believe that mathplotlib can do these things. What utility can I look into to better suit my needs?
I haven't used it myself but Chaco seems to fit some of your needs. It is more interactive than matplotlib and can be used to make quite interactive applications.
Chaco is a Python plotting application toolkit that facilitates writing plotting applications at all levels of complexity, from simple scripts with hard-coded data to large plotting programs with complex data interrelationships and a multitude of interactive tools. While Chaco generates attractive static plots for publication and presentation, it also works well for interactive data visualization and exploration.
(source: enthought.com)
QGraphicsScene/View from PyQt4 is a fantastic piece of code. Although your description makes me think that some upfront work will be necessary to make things work.
...don 't trust me, I'm biased ;) Get the library here and check the demos.
The equivalent of matplotlib in the PyQt world is PyQwt (matplotlib integrates with PyQt also, but with PyQwt the integration is smoother). Take a look at this comparison between matplotlib and PyQwt:
http://eli.thegreenplace.net/2009/06/05/plotting-in-python-matplotlib-vs-pyqwt/
PyQt + MathGL can do it easily. See this sample.
I've never done any UI programming in python before. What is the best (read most intuitive, easy to use, functional) UI package for python for doing simulations?
I'll be doing a simulation of TSP right now. So I'll have a graph (nodes and edges) where the edges are rapidly changing, along with some selection boxes to choose different styles of the algorithm, choose the number of nodes, etc..
I've already written this code with a command line interface and I'm hoping for something pretty seamless to port in a gui :)
I am not sure what you mean by "simulations" since the type of UI you want to do depends on what you simulate. But if you want to visualize graphs, networkx is pretty cool.
Such a simulation could be easily coded using:
networkx - for the graph data structures and algorithms
matplotlib - which is used by networkx to visualize graphs
Some GUI framework - PyQt, for instance, for the display and interaction with the user
What's cool is that these can be learned and tried separately. networkx is very powerful and can provide anything you need graph-vise. It works well with matplotlib, and you can show the steps of TSP by different colorings of edges/nodes. matplotlib can also be easily integrated with PyQt to put it all into a single interactive program.
Colleagues of mine are working on a similar-sounding setup to you - they use http://matplotlib.sourceforge.net/ and PyQt - PyQt can add a matplotlib object easily as a widget so the two integrate very well. A tutorial for PyQt is available here: http://www.zetcode.com/tutorials/pyqt4/
If you have graphs, you should definitely check out PyGraphviz (the interface is pretty similar to the aforementioned networkx)