Python Forum
How to automatically close mathplotlib output window?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to automatically close mathplotlib output window?
#1
I was hoping I could display the output window for a few seconds then close it automatically, but that's not happening.

What am I doing wrong?

def countLetters(code):    
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    letter_counts = [code.count(l) for l in alphabet]
    letter_colors = plt.cm.hsv([0.8*i/max(letter_counts) for i in letter_counts])
    plt.bar(range(26), letter_counts, color=letter_colors)
    plt.xticks(range(26), alphabet) # letter labels on x-axis
    plt.tick_params(axis="x", bottom=False) # no ticks, only labels on x-axis
    plt.title("Frequency of each letter")
    plt.show() # added by me
    time.sleep(6)
    plt.close()
Reply
#2
Running from command in non-interactive mode plt.show() GUI will block until the figures have been closed(bye you manually).
Can set plt.show(block=False) and also use plt.pause(6) it should work.
Tested work fine.
import matplotlib.pyplot as plt
import numpy as np

xaxis = np.array([2, 8])
yaxis = np.array([4, 9])
plt.plot(xaxis, yaxis)
plt.show(block=False)
plt.pause(6)
plt.close()
Pedroski55 likes this post
Reply
#3
Also tested, works fine for me too!

Thank you very much!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a way to call and focus any popup window outside of the main window app? Valjean 6 1,611 Oct-02-2023, 04:11 PM
Last Post: deanhystad
  Pyspark Window: perform sum over a window with specific conditions Shena76 0 1,131 Jun-13-2022, 08:59 AM
Last Post: Shena76
  Closing Threads and the chrome window it spawned from Tkinter close button law 0 1,670 Jan-08-2022, 12:13 PM
Last Post: law
  Mathplotlib - passing reference to axs to function qmfoam 5 2,903 Aug-17-2020, 09:02 PM
Last Post: qmfoam
  Change the output window size and display area issac_n 0 2,251 Apr-13-2018, 04:41 AM
Last Post: issac_n
  Close IDLE display window? Emerogork 14 7,932 Jan-03-2018, 02:17 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020