Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1114955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:05:01+00:00 2026-05-17T03:05:01+00:00

I embedded a matplotlib graph of a sphere into Tkinter. Now for some reason

  • 0

I embedded a matplotlib graph of a sphere into Tkinter. Now for some reason I’ve lost the ability to orbit the object, when dragging the mouse. Anyone have an idea of why this happened and how to fix this?

#!/usr/bin/env python
import matplotlib
matplotlib.use('TkAgg')


from mpl_toolkits.mplot3d import  axes3d,Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
from numpy import arange, sin, pi
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
from matplotlib.ticker import LinearLocator, FixedLocator, FormatStrFormatter

import Tkinter
import sys

class E(Tkinter.Tk):
    def __init__(self,parent):
        Tkinter.Tk.__init__(self,parent)
        self.parent = parent


        self.protocol("WM_DELETE_WINDOW", self.dest)
        self.main()

    def main(self):
        self.fig = plt.figure()
        self.fig = plt.figure(figsize=(3.5,3.5))
        ax = Axes3D(self.fig)



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





        t = ax.plot_surface(x, y, z,  rstride=4, cstride=4,color='lightgreen',linewidth=0)




        self.frame = Tkinter.Frame(self)
        self.frame.pack(padx=15,pady=15)

        self.canvas = FigureCanvasTkAgg(self.fig, master=self.frame)

        self.canvas.get_tk_widget().pack(side='top', fill='both')


        self.canvas._tkcanvas.pack(side='top', fill='both', expand=1)

        self.toolbar = NavigationToolbar2TkAgg( self.canvas, self )
        self.toolbar.update()
        self.toolbar.pack()

        self.btn = Tkinter.Button(self,text='button',command=self.alt)
        self.btn.pack(ipadx=250)

    def alt (self):
        print 9
    def dest(self):
        self.destroy()
        sys.exit()



if __name__ == "__main__":
    app = E(None)
    app.title('Embedding in TK')
    app.mainloop()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T03:05:01+00:00Added an answer on May 17, 2026 at 3:05 am

    You need to setup your canvas before you plot, so move the block of code below to after this line self.canvas._tkcanvas.pack(side='top', fill='both', expand=1)

            #Move this Code 
            ax = Axes3D(self.fig)
            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))
            t = ax.plot_surface(x, y, z,  rstride=4, cstride=4,color='lightgreen',linewidth=0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I embedded .NET's WebBrowser into a form that has some other buttons. The application
Many embedded engineers use c++, but some argue it's bad because it's object oriented?
I embedded a default media player into my webpage with the following html <object
Possible Duplicate: Embedded a *.exe into a dll I have a C# project -
I have a page with multiple Matplotlib figures embedded. The figures get inserted/manipulated via
We have some embedded documents that look like this: { _id : ObjectId(4e402353bc9f6ec5a6000001), first_name
I have youtube videos embedded like so: <object height=25 width=610><param name=movie value=http://www.youtube.com/v/GBApIkX0YN4&hl=en_US&color1=0xf4f4f4&color2=0xffffff&hd=0&fs=0&enablejsapi=1&playerapiid=ytplayer> </param> <param
I've embedded a LinkedIn Apply Now button on my page . But there are
I have an executable embedded into my app resources. ATM I use assembly reflection
I have successfully implemented embedded vimeo videos into my app, however i would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.