Re: [Matplotlib-users] How to make diagram x_label by time and x_lable can move automatic

2014-06-23 Thread 不坏阿峰
i have read demo before. when not line not move auto, it can . but while my
case is need the diagram is dynamic move, i do not know how to modify my
code. i have tried many times.but failed.


2014-06-21 21:22 GMT+07:00 Eric Firing :

> On 2014/06/21, 3:39 PM, 不坏阿峰 wrote:
> > is there someone can help me ?
>
> Posting a *simple*, self-contained example as a starting point would
> make it more likely that someone would understand your question.  Leave
> out everything that is irrelevant--I suspect all the gui and threading
> code is in that category.
>
> Also, although it is not directly related to your question, please note
> that you are using a horrible mixture of backend invocations, and even
> if it works now, it will do you no good in the long run.
>
> See the embedding examples: no matplotlib.use, no pylab, one and only
> one gui toolkit.
>
> I also suspect the answer to your question is at least partly in one of
> the examples of plotting with dates; dates and times are handled
> together.  Here is one such example:
>
> http://matplotlib.org/examples/pylab_examples/date_demo1.html
>
> Eric
>
> > many thanks
> >
> >
> > 2014-06-19 19:36 GMT+07:00 不坏阿峰  > >:
> >
> > Dear all
> >
> > could some expert can help me.
> > I have modify from one demo. but i do not how to change the x_lable
> > to time like H:M:S, and can move it.  i have try some way, but
> failed.
> >
> > hope some expert can do me a favor.
> > thanks a lot
> >
> > ##
> > # coding=utf-8
> > import os
> > import pprint
> > import random, time
> > import sys
> > from PyQt4 import QtGui, QtCore
> > from threading import *
> > import time
> > import datetime
> >
> > import matplotlib
> > matplotlib.use('WXAgg')
> > from matplotlib.figure import Figure
> > from matplotlib.backends.backend_qt4agg import \
> >  FigureCanvasQTAgg as FigCanvas, \
> >  NavigationToolbar2QT as NavigationToolbar
> > import numpy as np
> > import pylab
> > class DataGen(object):
> >  """ A silly class that generates pseudo-random data for
> >  display in the plot.
> >  """
> >  def __init__(self, init=50):
> >  self.data = self.init = init
> >  def next(self):
> >  self._recalc_data()
> >  return self.data
> >  def _recalc_data(self):
> >  delta = random.uniform(-0.5, 0.5)
> >  r = random.random()
> >  if r > 0.9:
> >  self.data += delta * 15
> >  elif r > 0.8:
> >  # attraction to the initial value
> >  delta += (0.5 if self.init > self.data else -0.5)
> >  self.data += delta
> >  else:
> >  self.data += delta
> >
> > class myThing():
> >  class myThread(Thread):
> >  def __init__(self):
> >  Thread.__init__(self)
> >  self.running = True
> >  self.vec = [0]
> >  self.dg = DataGen()
> >
> >  print "Initializing myThread..."
> >
> >  def run(self):
> >  print "Running myThread..."
> >  while self.running:
> >  time.sleep(1)
> >  self.vec.append(self.dg.next())
> >  print "Splat"
> >  def getVec(self):
> >  return self.vec
> >  def stop(self):
> >  self.running = False
> >  def __init__(self):
> >  self.theThread = self.myThread()
> >  self.threadRunning = True
> >  print "initializing myThing..."
> >  self.theThread.start()
> >  def __del__(self):
> >  self.theThread.stop()
> >  def getVec(self):
> >  #print self.theThread.vec[:]
> >  return self.theThread.vec[:]
> > class ApplicationWindow(QtGui.QMainWindow):
> >  """ The main window of the application
> >  """
> >  def __init__(self):
> >  QtGui.QMainWindow.__init__(self)
> >  self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
> >  self.setWindowTitle('Demo: dynamic matplotlib graph')
> >  self.thing1 = myThing()
> >  self.thing2 = myThing()
> >  self.starttime =  int(time.time())
> >
> >
> >  self.create_menu()
> >  #self.create_status_bar()
> >  self.create_main_panel()
> >  self.redraw_timer = QtCore.QTimer(self)
> >  QtCore.QObject.connect(self.redraw_timer,
> > QtCore.SIGNAL("timeout()"), self.on_redraw_timer)
> >  self.redraw_timer.start(4000)
> >  def create_menu(self):
> >  menu_file = QtGui.QMenu("&File", self)
> >  #menu_file.addAction(u'&Save plot', self.on_save_pl

Re: [Matplotlib-users] How to make diagram x_label by time and x_lable can move automatic

2014-06-21 Thread Eric Firing
On 2014/06/21, 3:39 PM, 不坏阿峰 wrote:
> is there someone can help me ?

Posting a *simple*, self-contained example as a starting point would 
make it more likely that someone would understand your question.  Leave 
out everything that is irrelevant--I suspect all the gui and threading 
code is in that category.

Also, although it is not directly related to your question, please note 
that you are using a horrible mixture of backend invocations, and even 
if it works now, it will do you no good in the long run.

See the embedding examples: no matplotlib.use, no pylab, one and only 
one gui toolkit.

I also suspect the answer to your question is at least partly in one of 
the examples of plotting with dates; dates and times are handled 
together.  Here is one such example:

http://matplotlib.org/examples/pylab_examples/date_demo1.html

Eric

> many thanks
>
>
> 2014-06-19 19:36 GMT+07:00 不坏阿峰  >:
>
> Dear all
>
> could some expert can help me.
> I have modify from one demo. but i do not how to change the x_lable
> to time like H:M:S, and can move it.  i have try some way, but failed.
>
> hope some expert can do me a favor.
> thanks a lot
>
> ##
> # coding=utf-8
> import os
> import pprint
> import random, time
> import sys
> from PyQt4 import QtGui, QtCore
> from threading import *
> import time
> import datetime
>
> import matplotlib
> matplotlib.use('WXAgg')
> from matplotlib.figure import Figure
> from matplotlib.backends.backend_qt4agg import \
>  FigureCanvasQTAgg as FigCanvas, \
>  NavigationToolbar2QT as NavigationToolbar
> import numpy as np
> import pylab
> class DataGen(object):
>  """ A silly class that generates pseudo-random data for
>  display in the plot.
>  """
>  def __init__(self, init=50):
>  self.data = self.init = init
>  def next(self):
>  self._recalc_data()
>  return self.data
>  def _recalc_data(self):
>  delta = random.uniform(-0.5, 0.5)
>  r = random.random()
>  if r > 0.9:
>  self.data += delta * 15
>  elif r > 0.8:
>  # attraction to the initial value
>  delta += (0.5 if self.init > self.data else -0.5)
>  self.data += delta
>  else:
>  self.data += delta
>
> class myThing():
>  class myThread(Thread):
>  def __init__(self):
>  Thread.__init__(self)
>  self.running = True
>  self.vec = [0]
>  self.dg = DataGen()
>
>  print "Initializing myThread..."
>
>  def run(self):
>  print "Running myThread..."
>  while self.running:
>  time.sleep(1)
>  self.vec.append(self.dg.next())
>  print "Splat"
>  def getVec(self):
>  return self.vec
>  def stop(self):
>  self.running = False
>  def __init__(self):
>  self.theThread = self.myThread()
>  self.threadRunning = True
>  print "initializing myThing..."
>  self.theThread.start()
>  def __del__(self):
>  self.theThread.stop()
>  def getVec(self):
>  #print self.theThread.vec[:]
>  return self.theThread.vec[:]
> class ApplicationWindow(QtGui.QMainWindow):
>  """ The main window of the application
>  """
>  def __init__(self):
>  QtGui.QMainWindow.__init__(self)
>  self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
>  self.setWindowTitle('Demo: dynamic matplotlib graph')
>  self.thing1 = myThing()
>  self.thing2 = myThing()
>  self.starttime =  int(time.time())
>
>
>  self.create_menu()
>  #self.create_status_bar()
>  self.create_main_panel()
>  self.redraw_timer = QtCore.QTimer(self)
>  QtCore.QObject.connect(self.redraw_timer,
> QtCore.SIGNAL("timeout()"), self.on_redraw_timer)
>  self.redraw_timer.start(4000)
>  def create_menu(self):
>  menu_file = QtGui.QMenu("&File", self)
>  #menu_file.addAction(u'&Save plot', self.on_save_plot,
>  # QtCore.Qt.CTRL + QtCore.Qt.Key_S)
>  menu_file.addSeparator()
>  menu_file.addAction(u'E&xit', self.on_exit,
>   QtCore.Qt.CTRL + QtCore.Qt.Key_X)
>  self.menuBar().addMenu(menu_file)
>  def create_main_panel(self):
>  self.panel = QtGui.QFrame(self)
>  self.setCentralWidget(self.panel)
>  self.init_plot()
>

Re: [Matplotlib-users] How to make diagram x_label by time and x_lable can move automatic

2014-06-21 Thread 不坏阿峰
is there someone can help me ?
many thanks


2014-06-19 19:36 GMT+07:00 不坏阿峰 :

> Dear all
>
> could some expert can help me.
> I have modify from one demo. but i do not how to change the x_lable to
> time like H:M:S, and can move it.  i have try some way, but failed.
>
> hope some expert can do me a favor.
> thanks a lot
>
> ##
> # coding=utf-8
> import os
> import pprint
> import random, time
> import sys
> from PyQt4 import QtGui, QtCore
>
> from threading import *
> import time
> import datetime
>
> import matplotlib
> matplotlib.use('WXAgg')
> from matplotlib.figure import Figure
> from matplotlib.backends.backend_qt4agg import \
> FigureCanvasQTAgg as FigCanvas, \
> NavigationToolbar2QT as NavigationToolbar
> import numpy as np
> import pylab
>
>
> class DataGen(object):
> """ A silly class that generates pseudo-random data for
> display in the plot.
> """
> def __init__(self, init=50):
> self.data = self.init = init
>
> def next(self):
> self._recalc_data()
> return self.data
>
> def _recalc_data(self):
> delta = random.uniform(-0.5, 0.5)
> r = random.random()
>
> if r > 0.9:
> self.data += delta * 15
> elif r > 0.8:
> # attraction to the initial value
> delta += (0.5 if self.init > self.data else -0.5)
> self.data += delta
> else:
> self.data += delta
>
> class myThing():
> class myThread(Thread):
> def __init__(self):
> Thread.__init__(self)
> self.running = True
> self.vec = [0]
> self.dg = DataGen()
>
> print "Initializing myThread..."
>
> def run(self):
> print "Running myThread..."
> while self.running:
> time.sleep(1)
> self.vec.append(self.dg.next())
> print "Splat"
>
> def getVec(self):
> return self.vec
>
> def stop(self):
> self.running = False
>
> def __init__(self):
> self.theThread = self.myThread()
> self.threadRunning = True
> print "initializing myThing..."
> self.theThread.start()
>
> def __del__(self):
> self.theThread.stop()
>
> def getVec(self):
> #print self.theThread.vec[:]
> return self.theThread.vec[:]
>
>
> class ApplicationWindow(QtGui.QMainWindow):
> """ The main window of the application
> """
>
> def __init__(self):
> QtGui.QMainWindow.__init__(self)
> self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
> self.setWindowTitle('Demo: dynamic matplotlib graph')
>
> self.thing1 = myThing()
> self.thing2 = myThing()
> self.starttime =  int(time.time())
>
>
> self.create_menu()
> #self.create_status_bar()
> self.create_main_panel()
>
> self.redraw_timer = QtCore.QTimer(self)
> QtCore.QObject.connect(self.redraw_timer,
> QtCore.SIGNAL("timeout()"), self.on_redraw_timer)
> self.redraw_timer.start(4000)
>
>
> def create_menu(self):
> menu_file = QtGui.QMenu("&File", self)
> #menu_file.addAction(u'&Save plot', self.on_save_plot,
> # QtCore.Qt.CTRL + QtCore.Qt.Key_S)
> menu_file.addSeparator()
> menu_file.addAction(u'E&xit', self.on_exit,
>  QtCore.Qt.CTRL + QtCore.Qt.Key_X)
>
> self.menuBar().addMenu(menu_file)
>
> def create_main_panel(self):
> self.panel = QtGui.QFrame(self)
> self.setCentralWidget(self.panel)
>
> self.init_plot()
> self.canvas = FigCanvas(self.fig)
> self.canvas.setMinimumHeight(150)
>
> #self.toolbar = NavigationToolbar(self.canvas, None)
> self.vbox = QtGui.QVBoxLayout()
> self.vbox.addWidget(self.canvas)
>
> self.panel.setLayout(self.vbox)
> #self.vbox.Fit(self)
>
> self.unit = 20
> width, height = self.geometry().width(), self.geometry().height()
> self.show()
>
> def init_plot(self):
> self.dpi = 100
> self.fig = Figure((5.0, 3.0), dpi=self.dpi)
>
> self.axes = self.fig.add_subplot(111, navigate=False)
> self.axes.set_axis_bgcolor('black')
>
> self.axes.set_title('Very important random data', size=10)
> self.axes.set_xlabel('Time flies like an arrow',size=10)
> self.axes.set_ylabel('Random is just random',size=10)
>
> pylab.setp(self.axes.get_xticklabels(), fontsize=8)
> pylab.setp(self.axes.get_yticklabels(), fontsize=8)
>
> self.plot_data = self.axes.plot(
> self.thing1.getVec(),
> linewidth=0.5,
> color=(1, 1, 0),
> #marker='o',
> label="set1",
> )[0]
> print  self.thing1.getVec(), "<<>>"
> self.plot_data2 = self.axes.plot(
> se

[Matplotlib-users] How to make diagram x_label by time and x_lable can move automatic

2014-06-19 Thread 不坏阿峰
Dear all

could some expert can help me.
I have modify from one demo. but i do not how to change the x_lable to time
like H:M:S, and can move it.  i have try some way, but failed.

hope some expert can do me a favor.
thanks a lot

##
# coding=utf-8
import os
import pprint
import random, time
import sys
from PyQt4 import QtGui, QtCore

from threading import *
import time
import datetime

import matplotlib
matplotlib.use('WXAgg')
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import \
FigureCanvasQTAgg as FigCanvas, \
NavigationToolbar2QT as NavigationToolbar
import numpy as np
import pylab


class DataGen(object):
""" A silly class that generates pseudo-random data for
display in the plot.
"""
def __init__(self, init=50):
self.data = self.init = init

def next(self):
self._recalc_data()
return self.data

def _recalc_data(self):
delta = random.uniform(-0.5, 0.5)
r = random.random()

if r > 0.9:
self.data += delta * 15
elif r > 0.8:
# attraction to the initial value
delta += (0.5 if self.init > self.data else -0.5)
self.data += delta
else:
self.data += delta

class myThing():
class myThread(Thread):
def __init__(self):
Thread.__init__(self)
self.running = True
self.vec = [0]
self.dg = DataGen()

print "Initializing myThread..."

def run(self):
print "Running myThread..."
while self.running:
time.sleep(1)
self.vec.append(self.dg.next())
print "Splat"

def getVec(self):
return self.vec

def stop(self):
self.running = False

def __init__(self):
self.theThread = self.myThread()
self.threadRunning = True
print "initializing myThing..."
self.theThread.start()

def __del__(self):
self.theThread.stop()

def getVec(self):
#print self.theThread.vec[:]
return self.theThread.vec[:]


class ApplicationWindow(QtGui.QMainWindow):
""" The main window of the application
"""

def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.setWindowTitle('Demo: dynamic matplotlib graph')

self.thing1 = myThing()
self.thing2 = myThing()
self.starttime =  int(time.time())


self.create_menu()
#self.create_status_bar()
self.create_main_panel()

self.redraw_timer = QtCore.QTimer(self)
QtCore.QObject.connect(self.redraw_timer,
QtCore.SIGNAL("timeout()"), self.on_redraw_timer)
self.redraw_timer.start(4000)


def create_menu(self):
menu_file = QtGui.QMenu("&File", self)
#menu_file.addAction(u'&Save plot', self.on_save_plot,
# QtCore.Qt.CTRL + QtCore.Qt.Key_S)
menu_file.addSeparator()
menu_file.addAction(u'E&xit', self.on_exit,
 QtCore.Qt.CTRL + QtCore.Qt.Key_X)

self.menuBar().addMenu(menu_file)

def create_main_panel(self):
self.panel = QtGui.QFrame(self)
self.setCentralWidget(self.panel)

self.init_plot()
self.canvas = FigCanvas(self.fig)
self.canvas.setMinimumHeight(150)

#self.toolbar = NavigationToolbar(self.canvas, None)
self.vbox = QtGui.QVBoxLayout()
self.vbox.addWidget(self.canvas)

self.panel.setLayout(self.vbox)
#self.vbox.Fit(self)

self.unit = 20
width, height = self.geometry().width(), self.geometry().height()
self.show()

def init_plot(self):
self.dpi = 100
self.fig = Figure((5.0, 3.0), dpi=self.dpi)

self.axes = self.fig.add_subplot(111, navigate=False)
self.axes.set_axis_bgcolor('black')

self.axes.set_title('Very important random data', size=10)
self.axes.set_xlabel('Time flies like an arrow',size=10)
self.axes.set_ylabel('Random is just random',size=10)

pylab.setp(self.axes.get_xticklabels(), fontsize=8)
pylab.setp(self.axes.get_yticklabels(), fontsize=8)

self.plot_data = self.axes.plot(
self.thing1.getVec(),
linewidth=0.5,
color=(1, 1, 0),
#marker='o',
label="set1",
)[0]
print  self.thing1.getVec(), "<<>>"
self.plot_data2 = self.axes.plot(
self.thing2.getVec(),
linewidth=1,
dashes=[.2, .4],
color=(0, 1, 1),
label="set2",
)[0]


def draw_plot(self):
""" Redraws the plot
"""
self.data = self.thing1.getVec()
self.data2 = self.thing2.getVec()
def do_cal(urdata):
newdata = []
for x in range(len