I'm wondering if anyone has advice or can direct me to information about how to render a graphviz or pygraphviz plot in a GUI. I'm generating ROS-like nodal plots using python and ideally I'd like to allow a user to interact with them. Thank you!
Related
I know this is "seeking for recommendations", but I have no experience with this.
I'm looking for a library for basic drawing in jupyter notebooks.
In particular I don't want libraries like plotly or matplotlib, since I don't need to draw graphs.
I'm looking for something like Canvas for JS.
I've already tested ipycanvas and tkinter but they don't work on DataSpell:
You can use the package turtle to produce drawings in Python.
I'm graphing some stuff with matplotlib and I need to be able to zoom in on the graph. But VSCode just renders it in its Python Interactive window that I can't do anything with. Is there a way to open graphs in a their own window that allows for scaling and things?
I'm a developer on this extension. We don't currently support popping out graphs. If you want to vote up the issue, we have an issue filed for this support here:
https://github.com/Microsoft/vscode-python/issues/4976
Until this support is added there is a bit of a work around. You can manually use the %matplotlib ipython magic to update to non-inline rendering. Then when you show plots they will be shown in a popup window. Like so:
I can't tell you exactly what command to use as it might vary based on what you have installed in your environment. But %matplotlib auto or %matplotlib qt would be good places to try starting with.
Plotly says it is a web library. Matplotlib does support Wxpython but comparatively, it is too low level. Is there any way to integrate Plotly inside a Wxpython GUI or are there any alternative for it?
You might be able to use Plotly's ability to export plots to images to get the plots into wxPython:
https://plot.ly/python/offline/#static-image-export
If you need the live plotting though, then you will need to use Webview:
https://wxpython.org/Phoenix/docs/html/wx.html2.WebView.html
I also see that Plotly can now be used offline, so if you used that plus Webview, it should work.
Wxpython webview doesn't support 3-d graphs from plotly.
For 3-d graphs, I used cefpython. It embeds a full chromium browser inside python application. wxpython example can be found here: https://github.com/cztomczak/cefpython/blob/master/examples/wxpython.py.
I used plotly offline, and read the file inside cefpython.
I have a list of value need to be drawn. The problem is have a format. How can I draw a graph with this kind of value. Im using python 2.7 with wxPython.
This is the link to the value, I cannot paste it here because the format will change
The wxPython project has a separate demo package you can download and install. Get that and look at the PyPlot demo. It can most simple plots just fine. If you need something more powerful, go download matplotlib. They have an example on their website for integrating matplotlib with wxPython. There is also an article or two on the wxPython wiki about matplotlib.
you can use matplotlib
there's lot of examples how embedding matplotlib figure in wxpython
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.