Adding plots to a frame in tkinter - python

I am creating a GUI interface that requires user input to conduct a cross-validation assessment on a dataset, and displaying 2 visualisations. My question is how to display these inside the tkinter frame. There is no real nice way of putting the code in, without having to put all of it on here, as all the data is linked to the output of the below confusion matrix (and the program is over 430 lines of code as it is) but essentially, I have a confusion matrix of:
conf_matrix = [[33 8],
[3 47]]
I know you can use ConfusionMatrixDisplay from sklearn.metrics to make the confusion matrix look a lot nicer, with coloured boxes, however, as I said above, really not sure how to put it into a frame inside my tkinter window, as I cannot find anywhere that explains the process of doing so.
I have tried to put it directly onto a canvas, but get an error saying that ConfusionMatrixDisplay doesn't have a set_canvas attribute.
The other visualisation is from matplotlib, however, I imagine that the process is the same to do this as well.
It is important to note too that the frame has used grid() throughout, as there are a lot of buttons, and it was just easier to grid it to make it look nice, so of course the graphs need to be able to be put in a grid if possible!
Any help would be greatly appreciated. Thanks!

Related

Wiskerplots are not clear enough to analyze data

I'm trying to analyze a set of costs using python.
The columns in the data frame are,
'TotalCharges', 'TotalPayments', 'TotalDirectVariableCost', 'TotalDirectFixedCost', 'TotalIndirectVariableCost', 'TotalIndirectFixedCost.
When I tried to plot them using the whisker plots, this is how they could display
I need to properly analyze these data and understand their behavior.
The following are my questions.
Is there any way that I can use wisker plots more clearly?
I believe since these are costs, we cannot ignore them as outliars. So keeping the data as it is what else I can use to represent data more clearly?
Thanks
There are a couple of things you could do:
larger print area
rotate the axis
plot one axis log scale
That said, I think you should examine once again your understanding of what a box and whisker plot is for.
Additionally, you might consider posting this on the Math or Cross Validated site as this doesn't have much to do with code.

How to buffer pyplot plots

TL;DR: I want to do something like
cache.append(fig.save_lines)
....
cache.load_into(fig)
I'm writing a (QML) front-end for a pyplot-like and matplotlib based MCMC sample visualisation library, and hit a small roadblock. I want to be able to produce and cache figures in the background, so that when the user moves some sliders, the plots aren't re-generated (they are complex and expensive to re-compute) but just brought in from the cache.
In order to do that I need to be able to do the plotting (but not the rendering) offline and then simply change the contents of a canvas. Effectively I want to do something like cache the
line = plt.plot(x,y)
object, but for multiple subplots.
The library produces very complex plots so I can't keep track of the line2D objects and use those.
My attempt at a solution: render to a pixmap with the correct DPI and use that. Issues arise if I resize the canvas, and not want to re-scale the Pixmaps. I've had situations where the wonderful SO community came up with much better solutions than what I had in mind, so if anyone has experience and/or ideas for how to get this behaviour, I'd be very much obliged!

Is there an equivalent to the Matlab figure window in Python (with all tools)?

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 :-)

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.

Interactive 2D plotting in python

I'm trying to write a program that creates a 2D grid in which the user chooses some edges between the points in the grid. Then the program dynamically manipulate those edges(eg. flip them, connect them, ...) till it converges to a particular shape.
Now my question is there any particular module that suits this kind of interactive plotting.
So far I've looked into PyQwt, GuiQwt, and Chaco but cannot figure out which one is more applicable for my program. It be great if someone could compare and contrast them, or suggest new modules.
Thanks
Have you tried PyGame or SFML?
Both support 'setting pixels' on a canvas.

Categories