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 7765255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:07:20+00:00 2026-06-01T15:07:20+00:00

I am trying to use matplotlib to create a graph to reflect real time

  • 0

I am trying to use matplotlib to create a graph to reflect real time results. I am probably not doing this correctly, because moving the window, changing windows, or clicking things causes the graph to freeze. Below is an example of what I mean.

import matplotlib
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np

def function1(fig, varse):
  ax = fig.add_subplot(111, projection='3d')
  color_grade_classes = ['#80FF00','#FFFF00','#FF8000', '#FF0000']
  varse = varse +1
  ax.set_xlabel('X')
  ax.set_ylabel('Y')
  for colors, rows  in zip(color_grade_classes, [3,2,1,0] ):  
    indexs = np.arange(5)
    heights = [varse,varse/2,varse/3,0,0]
    ax.bar(indexs, heights, zs = rows,  zdir='y', color=colors, alpha=0.8)
  plt.ion()
  plt.draw()
  plt.show()
  plt.ioff()
  return varse

varse = 0
plt.ion()
fig = plt.figure()
plt.ioff()
while(1):
  varse = function1(fig, varse)
  • 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-06-01T15:07:21+00:00Added an answer on June 1, 2026 at 3:07 pm

    The way I solved was to use tk as a gui:

    import matplotlib
    matplotlib.use('TkAgg')
    
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
    from matplotlib.figure import Figure
    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.pyplot as plt
    import random
    import numpy as np
    import sys
    import Tkinter as tk
    import time
    
    def function1(fig, ax):
        ax.cla()
        color_grade_classes = ['#80FF00','#FFFF00','#FF8000', '#FF0000']
        varsi =  random.randint(1, 100)
    
        for colors, rows  in zip(color_grade_classes, [3,2,1,0] ):  
            indexs = np.arange(5)
            heights = [varsi,varsi/2,varsi/3,0,0]
            ax.bar(indexs, heights, zs = rows,  zdir='y', color=colors, alpha=0.8)
        return fig
    
    class App():
        def __init__(self):
            self.root = tk.Tk()
            self.root.wm_title("Embedding in TK")
    
            self.fig = plt.figure()
            self.ax = self.fig.add_subplot(111, projection='3d')
            self.ax.set_xlabel('X')
            self.ax.set_ylabel('Y')
            self.fig = function1(self.fig, self.ax)
    
            self.canvas = FigureCanvasTkAgg(self.fig, master=self.root)
            self.toolbar = NavigationToolbar2TkAgg( self.canvas, self.root )
            self.toolbar.update()
            self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=1)
    
            self.label = tk.Label(text="")
            self.label.pack()
            self.update_clock()
            self.root.mainloop()
    
        def update_clock(self):
            self.fig = function1(self.fig,self.ax)
            self.canvas.show()
            self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=1)
            now = time.strftime("%H:%M:%S")
            self.label.configure(text=now)
            self.root.after(1000, self.update_clock)
    
    app=App()
    

    This allows me to retain control of the graph after I show and it doesn’t freeze up whenever I try to move the window.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This must be a really basic question: I am trying to use Matplotlib. Here's
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
I am trying to use networkx with Python. When I run this program it
I'm trying to use matplotlib to prepare some figures for publication. In order to
I am trying use MySql and Entity Framework, using Connector/Net 6.1 with this as
Anyone know how to create a cvCreateStructuringElementEx using a image? I'm trying use opencv.cv.cvCreateStructuringElementEx()
I'm trying use to selenium with firefox on CentOS from command line like this:
i'm trying use webview to load a image from sdcard i use this path
I'm trying to go away from matlab and use python + matplotlib instead. However,
I'm trying use epoch time dates in my series data. The array looks 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.