Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib Python Stealing Screen Focus

my code is taking serial data from an arduino, processing it, and then plotting it. I am using matplotlib as the graphics interface. Every time it 'draws' though it forces attention to it, and a user won't be able to look at anything besides that. What is the best way to get this to stop? (The code works fine except for the stealing focus). I tried to use the matplotlib.use('Agg') method after reading that on another post, but it did not work. (Using a MAC OS X).

The Code shown below is a super simple graph of updating data, with which I have the same problem. I'm not showing my code because it is not copy-pastable without the right inputs Here is my code:

import matplotlib
from matplotlib import *
from pylab import *
# import math


x=[]
y=[]
def function(iteration):
    xValue=iteration#Assigns current x value
    yValue=(1./iteration)*34#Assigns current y value

    x.extend([xValue]) #adds the current x value to the x list
    y.extend([yValue]) #adds the current y value to the y list


    clf() #clears the plot

    plot(x,y,color='green') #tells the plot what to do 
    draw() #forces a draw

def main():

    for i in range(1,25): #run my function 25 times (24 I think actually)
        function(i)
        pause(.1)

main()
like image 442
Michael Slater Avatar asked Jun 24 '13 23:06

Michael Slater


1 Answers

Have you tried using the interactive mode of matplotlib?

You can switch it on using ion() (see Documentation)

If you use interactive mode you do not need to call draw() but you might need to clear your figures using clf() depending on your desired output

like image 199
Mailerdaimon Avatar answered Sep 27 '22 21:09

Mailerdaimon