I'm using Qt4.8 via PyQt in a Python application. Everything is working fine :-) But I need to present the user with some kind of curve editor, these widgets commonly found in image editing programs for adjusting contrast or color or stuff like this.
So I basically need a widget, which displays a curve with axes and stuff like that and the user should be able to "drop" points onto the curve and adjust the curve.
I thought I could use matplotlib for this, but as far as I see it doesn't provide any "editing" capability...
I wrote a Qt curve editor with OpenGL widget, you can try it.
http://www.shannap.com/qt-curve-editor-en.html
What you probably want is the qwt toolbox. It's like matplotlib for Qt.
http://qwt.sourceforge.net/
It has all kind of neat funcitonality for plots and graphs. Though you won't get the exact thing you need without creating your own subclasses.
You can do curve editor with matplotlib. See for example this YouTube video: http://www.youtube.com/watch?v=nCv_MhaeFo8
And then check the event handling examples: http://matplotlib.sourceforge.net/examples/event_handling/index.html
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)
I'm just wondering if it exists an equivalent to the Matlab figure window in Python where we can modify plots directly from the figure window, or add some features (text, box , arrow, and so on), or make curve fitting, etc.
Matplotlib is good, but it is not as high-level as the Matlab figure. We need to code everything and if we want to modify plots, we need to modify the code directly (except for some basic stuffs like modifing the line color)
With matplotlib, you will indeed remain in the "code it all" workflow. This is not directly the answer you expect but the matplotlib documentation recently gained a very instructive figure that will probably help you if you stay with matplotlib: http://matplotlib.org/examples/showcase/anatomy.html shows the "anatomy" of the figure with all the proper designations for the parts of the figure.
Overall, I could always find examples of what I needed in their excellent gallery http://matplotlib.org/gallery.html
In my opinion, you'll save time by coding these customizations instead of doing them by hand. You may indeed feel otherwise but if not there is a ton of examples of matplotlib code on SO, in their docs and a large community of people around it :-)
I'm new to wxpython but have been a matplotlib user for some time now. I am developing a wxpython app in which I would like to have a simple frame with a single panel (actually, a wx.lib.plot.PlotCanvas instance). In the panel I want to show some data, which is in the form of a binary array (called imarr), like this one:
The array will always be of shape (64,N), and N can vary between about 400 and 1200 (I can sort out the panel sizing myself).
To do this in matplotlib I would use something like:
fig=figure(figsize=(12,2))
ax=fig.add_subplot(111)
ax.set_ylim(0,63)
ax.set_xlim(0,imarr.shape[0])
ax.set_aspect('equal')
matplotlib.imshow(imarr)
But I'm completely lost in wxpython. I have been looking into wx.lib.plot, but apart from the nice line and marker plotting capabilities, there doesn't seem to be an equivalent to imshow (or pcolor).
One (ugly) solution I have is to use matplotlib as above to create a png image and then use some wx magic to display the image on a panel (please set me straight if this won't be easy).
I'd much prefer to do it from within wxpython, for portability and general tidiness. Any advice on how to display a binary array on a wx.lib.plot.PlotCanvas (or a more generic wx.Panel) would be very useful!
Why don't you combine wxPython and matplotlib together? wx.lib.plot.PlotCanvas has limited functionality comparing to matplotlib. Have a look at an example in this answer and an example from the matplotlib documentation. Sorry that I didn't answer exactly what you are asking for but I think this is the right way to go.
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)
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.