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()
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With