Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running matplotlib in tkinter

Tags:

I have this beautiful sphere I made in matplotlib. How would I go about putting it in a tkinter frame widget? It'd be nice to be able to integrate it into an existing tkinter GUI. Also is it possible to rid of the menu bar below the display? I have no need to save the output or zoom, so it's useless to me.

from mpl_toolkits.mplot3d import  axes3d,Axes3D import matplotlib.pyplot as plt from matplotlib import cm import numpy as np  fig = plt.figure() ax = Axes3D(fig) #<-- Note the difference from your original code..  u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100)  x = 10 * np.outer(np.cos(u), np.sin(v)) y = 10 * np.outer(np.sin(u), np.sin(v)) z = 10 * np.outer(np.ones(np.size(u)), np.cos(v))  ax.plot_surface(x, y, z,  rstride=4, cstride=4, color='lightgreen',linewidth=0) #,antialiased=False #cmap=cm.jet plt.show() 
like image 998
rectangletangle Avatar asked Oct 02 '10 11:10

rectangletangle


People also ask

Can we use matplotlib with Tkinter?

Python Matplotlib library is helpful in many applications for visualizing the given data and information in terms of graphs and plots. It is possible to run matplotlib in a Tkinter application.

Can you use matplotlib in Python?

Matplotlib is a cross-platform, data visualization and graphical plotting library for Python and its numerical extension NumPy. As such, it offers a viable open source alternative to MATLAB. Developers can also use matplotlib's APIs (Application Programming Interfaces) to embed plots in GUI applications.

How do I run Tkinter GUI?

Tkinter ProgrammingImport the Tkinter module. Create the GUI application main window. Add one or more of the above-mentioned widgets to the GUI application. Enter the main event loop to take action against each event triggered by the user.

Can you use Plotly with Tkinter?

This means that it is not possible to have tkinter directly handle plotly user interactive events. The closest to what you want would hence be to generate a non interactive plotly rendering eg a png/jpg and display it in a tkinter canvas.


1 Answers

Have a look at the examples for embedding plots in a tk GUI, it should be enough to get you started in the right direction.

user_interfaces example code: embedding_in_tk.py

user_interfaces example code: embedding_in_tk2.py

As for removing the toolbar, it's a case of not adding it when you are embedding plots in a GUI.

If you are using matplotlib.pyplot the toolbar will be created automatically for every figure. If you are writing your own user interface code, you can add the toolbar as a widget.

like image 160
volting Avatar answered Oct 26 '22 05:10

volting