1

I have modified some code I found to produce a GUI containing a Matplotlib figure.

This is the first stage in my GUI construction, I also need to add parameters for the user to change and an update button. But first I want to get this working. I currently have 6 subplots, all of which are projected onto a 3D axis. Now I would like to be able to rotate the axis ideally using a mouse, either rotating each axis individually or rotating all 6 as a group. I am currently unable to rotate anything

Is this possible? Please can you help me update this code?

I am using Python 3.5 Anaconda distribution on Spyder in Windows 10

Thanks

import matplotlib
matplotlib.use('TkAgg')

import numpy as np
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
# implement the default mpl key bindings
from matplotlib.backend_bases import key_press_handler


from matplotlib.figure import Figure

import sys
if sys.version_info[0] < 3:
    import Tkinter as Tk
else:
    import tkinter as Tk

root = Tk.Tk()
root.wm_title("Embedding in TK")


fig = Figure(figsize=(5, 4), dpi=100)
a = fig.add_subplot(231, projection = '3d')
b = fig.add_subplot(232, projection = '3d')
c = fig.add_subplot(233, projection = '3d')
d = fig.add_subplot(234, projection = '3d')
e = fig.add_subplot(235, projection = '3d')
f = fig.add_subplot(236, projection = '3d')

x = np.arange(0.0, 3.0, 0.01)
y = np.arange(3.0, 0.0, -0.01)
s = np.sin(2*np.pi*x)
cos = np.cos(2*np.pi*x)
t = np.tan(2*np.pi*x)


a.plot(x, y, s)
b.plot(x, y, cos)
c.plot(x, y, t)



# a tk.DrawingArea
canvas = FigureCanvasTkAgg(fig, master=root)
canvas.show()
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)

toolbar = NavigationToolbar2TkAgg(canvas, root)
toolbar.update()
canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)


def on_key_event(event):
    print('you pressed %s' % event.key)
    key_press_handler(event, canvas, toolbar)

canvas.mpl_connect('key_press_event', on_key_event)


def _quit():
    root.quit()     # stops mainloop
    root.destroy()  # this is necessary on Windows to prevent
                    # Fatal Python Error: PyEval_RestoreThread: NULL tstate

button = Tk.Button(master=root, text='Quit', command=_quit)
button.pack(side=Tk.BOTTOM)

Tk.mainloop()
jlt199
  • 2,349
  • 6
  • 23
  • 43
  • You may want to adapt the code from **[this question](http://stackoverflow.com/questions/41167196/using-matplotlib-3d-axes-how-to-drag-two-axes-at-once)**, which shows how to synchronize the rotation and zoom events between different 3D subplots. – ImportanceOfBeingErnest Mar 23 '17 at 18:13
  • Thanks, but at the moment I don't have rotation of any sort and I don't this example helps me make the leap to getting anything to rotate – jlt199 Mar 23 '17 at 19:15
  • I that case you may need to better describe the problem you are having. – ImportanceOfBeingErnest Mar 23 '17 at 21:47

0 Answers0