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

  • Home
  • SEARCH
  • 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 1898482
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:46:13+00:00 2026-05-17T06:46:13+00:00

I have below a code that will plot a sphere, it’s proportions are defined

  • 0

I have below a code that will plot a sphere, it’s proportions are defined by prop, I’d like it so when the button is pressed prop‘s value changes to 5 and the graph is adjusted accordingly. How do I go about this?

I know tkinter has .configure(), which allows one to adjust widget settings. I’m looking for something similar so that I can reconfigure my plot.

#!/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)


        prop = 10

        u = np.linspace(0, 2 * np.pi, 100)
        v = np.linspace(0, np.pi, 100)

        x = prop * np.outer(np.cos(u), np.sin(v))
        y = prop * np.outer(np.sin(u), np.sin(v))
        z = prop * 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):
        prop = 5
    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-17T06:46:14+00:00Added an answer on May 17, 2026 at 6:46 am

    Modify main function in class E:

     def main(self):
            self.fig = plt.figure()
            self.fig = plt.figure(figsize=(3.5,3.5))
    
            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)
    
            self.draw_sphere()
    

    Function alt is:

     def alt (self):
            self.draw_sphere(5)
    

    and add new function draw_sphere (also in class E):

     def draw_sphere(self, prop=10):
            self.fig.clear()
            ax = Axes3D(self.fig)
    
            u = np.linspace(0, 2 * np.pi, 100)
            v = np.linspace(0, np.pi, 100)
    
            x = prop * np.outer(np.cos(u), np.sin(v))
            y = prop * np.outer(np.sin(u), np.sin(v))
            z = prop * 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.canvas.draw()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a chart (code to replicate will be below) that has two lines
I have code that looks more or less like the code below but it
I have the code below. I'm wondering that does the self.value and _value have
I have a plot (sample code pasted below) that I am trying to add
I have the code below that will open a modal window. This works in
I have python code below that will loop through a table and print out
I have this code below that supposedly will detect duplicate id generation and will
I have the code below that hides and shows the navigational bar. It is
I have this javascript code below that uses jquery, it is suppoed to be
below i have a code that runs in most of my simple programs ..

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.