Python Plotting and displaying multiple objects in same GUI window - python

I have a 2 part question:
what is the best method for plotting data in Python? I only need to plot data in 2d.
I have a canvas GUI that I built using Tkinter's canvas function. It draws an 8x8 grid of rectangles and also has some code to allow you to scroll the window. (I've attached a picture).
Is it possible to include a plot in the same window as this canvas object? I need to be able to display plotted data and hopefully add buttons to my GUI that will allow me to update the plot during the run of the GUI.
Thanks in advance!

Matplotlib is the de-facto way to plot data with Python. It's really wonderful. It can also be embedded in Tk.

Related

Exporting data and graphs from a python GUI into a single file

I have made a GUI with qt designer and python. In this GUI i have multiple tabs. In some tabs i display a matplotlib widget and in some tabs i display a textedit. After pressing a button lines will be plotted in the matplotlib widgets and in the textedit some data will be displayed. How can i get these matplotlib graphs and the data from the textedits into one file after pressing an 'export' button?
The question doesn't specify many constraints, but if one big honking image is sufficient, you can take snapshots of the relevant widgets using Qt5 or Qt4 and just tile them into gigantic image:
After calling QWidget::grab or Pixmap::grabWidget, find the most reasonable layout for all the widgets and calculate the total size. Then create one gigantic QPixmap and render them via QPainter::drawPixmap to the appropriate coordinates into the combined image.
Of course, this seems pretty ugly and questionable to me, but I'm not one to second-guess what you want to do either... just know that I realize this is kind of icky.

PyQtGraph : how to change size (height and width) of graph in a ScrollArea

I'm trying to plot graph in a scroll area but I've no idea how to change the size of my graphs. Here is an example of what I have:
As you can see, in my ScrollArea (in Red) which as the size I want, I have a graph (well, in reallity I have more graphs and I want to see more then one (at least two) in this area).
So, I want the height of my graph (A) to be smaller and the width of my graph (B) to be expanding. Somine can help me ?
Thanks for your help !
It looks like your plot is inside a layout with the "Hide EMG" button. The widget holding that layout must be resized to fit the scroll area. You'll need to provide a code sample if you want more help than that..
Also consider using pg.MultiPlotWidget, which already provides similar functionality.
Adding to Lukes comment: A PlotWidget, which is probably what we see there, is a QGraphicsView, which is a QWidget. This is layed out using Qt. I'd recommend you to play a bit with Qt Designer to get an intuition on how the layouting works.
Another resource would be: https://doc.qt.io/qt-5/layout.html
For your explicit problem, if you do not want to get into Qt layouting, you could use QWidget.setMinimumHeight and QWidget.setMaximumHeight to confine the widget vertically. For the horizontal part, that totally depends on what you are doing there. If that was a grid layout, I'd refer to e.g.: Expanding only one column in a QGridLayout

Python, matplotlib, wxpython - Anyway to move an canvas from one frame to another?

So I don't really have any code to show as it's a very large script I have currently. Having said that I will try and add a simple example shortly.
Basically lets say I have two frames in wxpython, each containing a single panel with a matplotlib canvas. Lets call these canvases graph1 and graph2.
So I know how to plot directly into graph1, using standard methods.
I was wondering if there is any way I could change the location of graph1 into that of graph2, i.e. move the plot to the second frame (window).
Basically I am trying to implement a full screen option for the user, which upon clicking a graph will maximise it into the second frame. I am hoping I can do this just by changing the references rather than re-drawing etc. as I want it to keep the original state of the graph when it maximises.

embedding grid in panel in wxpython

What is the proper way to embedd grid (wx.grid.Grid) into the panel? I tried the following code and got bizarre frame:
wx.Frame.__init__(self,wx.GetApp().TopWindow,size=(600,800),title='Material Properties')
self.GridPanel=wx.Panel(self,-1)
grid=wx.grid.Grid(self.GridPanel,-1)
grid.CreateGrid(10,10)
I cannot see an easy way to create a grid which can also have buttons as well as menubar and other related widgets. Is there any example which shows GUI of how to implement wx.grid to achieve some sort of spreadsheet which has tabs on it for manipulation. I seem to be lost on this.
I want to create two different grid and also want to add some buttons and additional functionalites to the frame containing the table. Is there any better way to do that in wxpython?
I wrote about grids quite a while ago on my blog. You might find the following articles helpful for putting a Grid onto a Panel:
http://www.blog.pythonlibrary.org/2010/04/04/wxpython-grid-tips-and-tricks/
http://www.blog.pythonlibrary.org/2010/03/18/wxpython-an-introduction-to-grids/
Once you have that figured out, you can easily put the panel into a Notebook. If you want to add buttons, create the buttons and then add them to the sizer (see second example). Adding a Toolbar to the frame is covered in the wxPython demo, but I covered it here too:
http://www.blog.pythonlibrary.org/2008/07/02/wxpython-working-with-menus-toolbars-and-accelerators/

How do I control where an R plot is displayed, using python and rpy2?

I'm writing a program in Python. The first thing that happens is a window is displayed (I'm using wxPython) that has some buttons and text. When the user performs some actions, a plot is displayed in its own window. This plot is made with R, using rpy2. The problem is that the plot usually pops up on top of the main window, so the user has to move the plot to see the main window again. This is a big problem for the user, because he's lazy and good-for-nothing. He wants the plot to simply appear somewhere else, so he can see the main window and the plot at the same time, without having to lift a finger.
Two potential solutions to my problem are:
(1) display the plot within a wxPython frame (which I think I could control the location of), or
(2) be able to specify where on the screen the plot window appears.
I can't figure out how to do either.
Plot to a graphics file using jpeg(), png() or another device, then display that file on your wxWidget.
There are few lines about this in the documentation:
http://rpy.sourceforge.net/rpy2/doc-2.2/html/graphics.html
By default R plots to the "interactive" plotting device (X11). Specifying a non-interactive file-based device (jpeg, png, pdf - pdf being probably easier if rescaling or zooming is wished).
There is a very experimental feature in rpy2-2.2.0dev that would let one implement relatively easily new devices (e.g., plot into matplotlib canvases, or wxWindows panels), but unfortunately this is not complete, not documented, and probably not fully working.

Categories