Re: [Matplotlib-users] plot a data stream with matplotlib

2009-01-19 Thread Simone Gabbriellini
I see that you first build your array and then display it at the end...

is it possible in matplotlib to update the plot while the class is
evolving? like:

f.evolve(6)
f.display()
f.evolve(.27)
f.display()
f.evolve(10)
f.display()
f.evolve(2)
f.display()

best regards,
simone

2009/1/19 C Lewis chle...@nature.berkeley.edu:
 #Skeleton example of a taking snapshots of an evolving class
 import pylab as p
 from math import log
 class foo:
def __init__(self):
self.red = 0
self.green = 1
self.age = 0
self.history = ([self.age],[self.red],[self.green])

def snapshot(self):
self.history[0].append(self.age)
self.history[1].append(self.red)
self.history[2].append(self.green)

def evolve(self, time):
self.red = self.red + time/2
self.green = self.green * log(time)
self.age = self.age + time
self.snapshot()

def display(self):

  p.plot(self.history[0],self.history[1],self.history[0],self.history[2])
p.show()

 if __name__ == '__main__':
f = foo()
f.snapshot()
f.evolve(6); f.evolve(.27);f.evolve(10);f.evolve(2)
print f.history
f.display()

 On Jan 18, 2009, at 3:18 PM, Simone Gabbriellini wrote:

 thanks, it is exactly what I need... I have undestood the logic, I
 build a plot,  put my traits values into an array and then I call the
 add_current_state_to_plot function to update the plot with the new
 values...

 I am an absolute beginner of matplotlib, can you give me a little
 example of add_current_state_to_plot function? Because I don't know
 the right way to update: do I have to pass all the array, or just the
 new values?

 best regards,
 simone

 2009/1/18 C Lewis chle...@nature.berkeley.edu:

 Guessing about what you want:

 Does the class change with time? that is, perhaps you have a class foo,
 and
 foo evolves, and you would like to plot a history of some traits of foo,
 but
 at any given moment foo only contains its current state?

 If so, I think you need to have a function in foo, or even a separate
 class,
 that takes `snapshots' of foo's traits on one schedule, and stores them,
 and
 can also plot them on some schedule. Choosing how to do that is more a
 python problem than a matplotlib problem; personally, I have something
 set
 up so class 'profile' has functions to 'setup_plot' and
 'add_current_state_to_plot', and I just have to choose when to call the
 latter.

 Or you can just store the values and plot at the end; once you have one
 list
 of the times, and a separate list of each trait's history at those times,
 you're set up for matplotlib plotting, e.g.

 from pylab import *
 plot(times, traitA, times, traitB, times, traitC)
 show()

 although, while looking for a simple example, I found this:


 http://matplotlib.sourceforge.net/examples/pylab_examples/plotfile_demo.html

 which is not totally simple but looks great.


 C

 On Jan 18, 2009, at 9:36 AM, Simone Gabbriellini wrote:

 Dear List,

 I have some variables I want to plot... the values of those variable
 change in time... I would like to plot the result with a traditional
 line plot

 those variables are traits of a class (don't know if this can make a
 difference...)

 is there any example of this with matplotlib?

 best regards,
 simone gabbriellini



 --
 This SF.net email is sponsored by:
 SourcForge Community
 SourceForge wants to tell your story.
 http://p.sf.net/sfu/sf-spreadtheword
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users



 Chloe Lewis
 Graduate student, Amundson Lab
 Division of Ecosystem Sciences, ESPM
 University of California, Berkeley
 137 Mulford Hall - #3114
 Berkeley, CA  94720-3114
 chle...@nature.berkeley.edu



--
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Building matplotlib from source - compile error - defined in discarded section - _backend_agg.so

2009-01-19 Thread Anders.Strandberg
Hi,

I have been trying to build matplotlib on SLED 10:

+ python setup.py build

BUILDING MATPLOTLIB
matplotlib: 0.98.5.2
python: 2.5.2 (r252:60911, Aug 21 2008, 18:45:08)  [GCC
3.3.6]
  platform: linux2

REQUIRED DEPENDENCIES
 numpy: 1.2.1
 freetype2: found, but unknown version (no pkg-config)

OPTIONAL BACKEND DEPENDENCIES
libpng: found, but unknown version (no pkg-config)
   Tkinter: Tkinter: 50704, Tk: 8.4, Tcl: 8.4
* Guessing the library and include directories for
* Tcl and Tk because the tclConfig.sh and
* tkConfig.sh could not be found and/or parsed.
  wxPython: no
* wxPython not found
  Gtk+: no
* Building for Gtk+ requires pygtk; you must be able
* to import gtk in your build/install environment
   Mac OS X native: no
Qt: no
   Qt4: no
 Cairo: no

OPTIONAL DATE/TIMEZONE DEPENDENCIES
  datetime: present, version unknown
  dateutil: matplotlib will provide
  pytz: matplotlib will provide
adding pytz

OPTIONAL USETEX DEPENDENCIES
dvipng: no
   ghostscript: 7.05
 latex: no
   pdftops: 3.01

[Edit setup.cfg to suppress the above messages]






 but have encountered some problems:


g++ -pthread -shared -L/app/gcc/3.3.6/lib -L/app/zlib/1.2.x/lib 
-L/app/tk/8.4.x/lib -L/app/tcl/8.4.x/lib -L/app/readline/5.0/lib 
-L/app/openssl/0.9.x/lib -L/app/ncurses/5.5/lib -L/app/gdbm/1.8.3/lib 
-L/app/expect/5.x/lib -L/app/expat/2.0.x/lib -L/app/db/4.3.x/lib 
-L/usr/X11R6/lib 
-Wl,--rpath=/app/Python/2.5.x/lib:/app/gcc/3.3.6/lib:/app/zlib/1.2.x/lib:/app/tk/8.4.x/lib:/app/tcl/8.4.x/lib:/app/readline/5.0/lib:/app/openssl/0.9.x/lib:/app/ncurses/5.5/lib:/app/gdbm/1.8.3/lib:/app/expect/5.x/lib:/app/expat/2.0.x/lib:/app/db/4.3.x/lib:/usr/X11R6/lib
 -L /app/Python/2.5.x/lib -L/app/gcc/3.3.6/lib -L/app/zlib/1.2.x/lib 
-L/app/tk/8.4.x/lib -L/app/tcl/8.4.x/lib -L/app/libpng/1.2.x/lib 
-L/app/freetype/2.1.x/lib -L/usr/X11R6/lib 
-Wl,--rpath=/app/Python/modules/2.5/matplotlib/0.98.5.2/lib:/app/gcc/3.3.6/lib:/app/zlib/1.2.x/lib:/app/tk/8.4.x/lib:/app/tcl/8.4.x/lib:/app/libpng/1.2.x/lib:/app/freetype/2.1.x/lib:/usr/X11R6/lib
 -O2 -g -march=i386 -mcpu=i686 -fno-strict-aliasing 
build/temp.linux-i686-2.5/agg24/src/agg_trans_affine.o 
build/temp.linux-i686-2.5/agg24/src/agg_bezier_arc.o 
build/temp.linux-i686-2.5/agg24/src/agg_curves.o 
build/temp.linux-i686-2.5/agg24/src/agg_vcgen_dash.o 
build/temp.linux-i686-2.5/agg24/src/agg_vcgen_stroke.o 
build/temp.linux-i686-2.5/agg24/src/agg_image_filters.o 
build/temp.linux-i686-2.5/src/_image.o build/temp.linux-i686-2.5/src/ft2font.o 
build/temp.linux-i686-2.5/src/mplutils.o 
build/temp.linux-i686-2.5/CXX/cxx_extensions.o 
build/temp.linux-i686-2.5/CXX/cxxsupport.o 
build/temp.linux-i686-2.5/CXX/IndirectPythonInterface.o 
build/temp.linux-i686-2.5/CXX/cxxextensions.o 
build/temp.linux-i686-2.5/src/backend_agg.o -L/app/libpng/1.2.x/lib 
-L/app/freetype/2.1.x/lib -L/app/tcl/8.4.x/lib -L/app/tk/8.4.x/lib 
-L/app/libpng/1.2.x/lib -L/app/freetype/2.1.x/lib -L/app/tcl/8.4.x/lib 
-L/app/tk/8.4.x/lib -L/app/Python/2.5.x/lib -lstdc++ -lm -lfreetype -lz 
-lstdc++ -lm -lpython2.5 -o 
build/lib.linux-i686-2.5/matplotlib/backends/_backend_agg.so
`.L53185' referenced in section `.rodata' of 
build/temp.linux-i686-2.5/src/backend_agg.o: defined in discarded section 
`.gnu.linkonce.t._ZN3agg18rasterizer_sl_clipINS_12ras_conv_intEE7line_toINS_19rasterizer_cells_aaINS_7cell_aaEvRT_ii'
 of build/temp.linux-i686-2.5/src/backend_agg.o
`.L53186' referenced in section `.rodata' of 
build/temp.linux-i686-2.5/src/backend_agg.o: defined in discarded section 
`.gnu.linkonce.t._ZN3agg18rasterizer_sl_clipINS_12ras_conv_intEE7line_toINS_19rasterizer_cells_aaINS_7cell_aaEvRT_ii'
 of build/temp.linux-i686-2.5/src/backend_agg.o
`.L53196' referenced in section `.rodata' of 
build/temp.linux-i686-2.5/src/backend_agg.o: defined in discarded section 
`.gnu.linkonce.t._ZN3agg18rasterizer_sl_clipINS_12ras_conv_intEE7line_toINS_19rasterizer_cells_aaINS_7cell_aaEvRT_ii'
 of build/temp.linux-i686-2.5/src/backend_agg.o
`.L53206' referenced in section `.rodata' of 
build/temp.linux-i686-2.5/src/backend_agg.o: defined in discarded section 
`.gnu.linkonce.t._ZN3agg18rasterizer_sl_clipINS_12ras_conv_intEE7line_toINS_19rasterizer_cells_aaINS_7cell_aaEvRT_ii'
 of build/temp.linux-i686-2.5/src/backend_agg.o
`.L53207' referenced in section `.rodata' of 
build/temp.linux-i686-2.5/src/backend_agg.o: defined in discarded section 

[Matplotlib-users] bug in NavigationToolbar2QT ?

2009-01-19 Thread Michael Dovrat
I have noticed that in the NavigationToolbar2QT there is a small display of
x,y coordinates at the rightmost corner of the toolbar.

However, when using Axes.set_ticklabels, for example, to normalize through
the labels and not through the data itself or to make a reciprocal scale -
set locations and labels, the display of coordinates is lost.

I have attached the example embedding in qt4 with minimal additions to
show this.
Notice how the x coordinate is still alive in the bottom toolbar, while the
y coordinate isn't.

I haven't found any way in the documentation to tell the navigation toolbar
anything related to this change.

This isn't crucial in any way, just a pity that it is not working properly.

Miki

My operating system is Windows XP.
matplotlib version 0.98.5.2 on python 2.5 installed by the standard binary
installer.
#!/usr/bin/env python

# embedding_in_qt4.py --- Simple Qt4 application embedding matplotlib canvases
#
# Copyright (C) 2005 Florent Rougon
#   2006 Darren Dale
#
# This file is an example program for matplotlib. It may be used and
# modified with no restriction; raw copies as well as modified versions
# may be distributed without limitation.

import sys, os, random
from PyQt4 import QtGui, QtCore

from numpy import arange, sin, pi
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4 import NavigationToolbar2QT as 
NavigationToolbar


progname = os.path.basename(sys.argv[0])
progversion = 0.1


class MyMplCanvas(FigureCanvas):
Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.).
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
# We want the axes cleared every time plot() is called
self.axes.hold(False)

self.compute_initial_figure()

#
FigureCanvas.__init__(self, fig)
self.setParent(parent)

FigureCanvas.setSizePolicy(self,
   QtGui.QSizePolicy.Expanding,
   QtGui.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)

def compute_initial_figure(self):
pass


class MyStaticMplCanvas(MyMplCanvas):
Simple canvas with a sine plot.
def compute_initial_figure(self):
t = arange(0.0, 3.0, 0.01)
s = sin(2*pi*t)
self.axes.plot(t, s)


class MyDynamicMplCanvas(MyMplCanvas):
A canvas that updates itself every second with a new plot.
def __init__(self, *args, **kwargs):
MyMplCanvas.__init__(self, *args, **kwargs)
timer = QtCore.QTimer(self)
QtCore.QObject.connect(timer, QtCore.SIGNAL(timeout()), 
self.update_figure)
timer.start(1000)

def compute_initial_figure(self):
 self.axes.plot([0, 1, 2, 3], [1, 2, 0, 4], 'r')

def update_figure(self):
# Build a list of 4 random integers between 0 and 10 (both inclusive)
l = [ random.randint(0, 10) for i in xrange(4) ]

self.axes.plot([0, 1, 2, 3], l, 'r')
self.axes.yaxis.set_ticklabels([1, 2, 3])
self.draw()


class ApplicationWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.setWindowTitle(application main window)

self.file_menu = QtGui.QMenu('File', self)
self.file_menu.addAction('Quit', self.fileQuit,
 QtCore.Qt.CTRL + QtCore.Qt.Key_Q)
self.menuBar().addMenu(self.file_menu)

self.help_menu = QtGui.QMenu('Help', self)
self.menuBar().addSeparator()
self.menuBar().addMenu(self.help_menu)

self.help_menu.addAction('About', self.about)

self.main_widget = QtGui.QWidget(self)

l = QtGui.QVBoxLayout(self.main_widget)
sc = MyStaticMplCanvas(self.main_widget, width=5, height=4, dpi=100)
dc = MyDynamicMplCanvas(self.main_widget, width=5, height=4, dpi=100)
toolbar = NavigationToolbar(dc, dc)
l.addWidget(sc)
l.addWidget(dc)
l.addWidget(toolbar)

self.main_widget.setFocus()
self.setCentralWidget(self.main_widget)

self.statusBar().showMessage(All hail matplotlib!, 2000)

def fileQuit(self):
self.close()

def closeEvent(self, ce):
self.fileQuit()

def about(self):
QtGui.QMessageBox.about(self, About %s % progname,
u%(prog)s version %(version)s
Copyright \N{COPYRIGHT SIGN} 2005 Florent Rougon, 2006 Darren Dale

This program is a simple example of a Qt4 application embedding matplotlib
canvases.

It may be used and modified with no restriction; raw copies as well as
modified versions may be distributed without limitation.
% {prog: progname, version: progversion})


qApp = QtGui.QApplication(sys.argv)

aw = ApplicationWindow()

[Matplotlib-users] Extending a plot outside of axes

2009-01-19 Thread Einar M. Einarsson
Hi all.

is it not possible to extend plot outside of a plot area? To  
illustrate what I want
to do take for example the wind barbs example from the matplotlib  
gallery.
(see below)

I only changed line 23 from ax.barbs(X, Y, U, V) to ax.barbs(X, Y, - 
U, -V)

But now we don't see the tail of the barbs in the first subplot.

So Is it possible to let matplotlib plot the tail, without extending  
the axes?

Best Regards
Einar M. Einarsson

'''
Demonstration of wind barb plots
'''
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-5, 5, 5)
X,Y = np.meshgrid(x, x)
U, V = 12*X, 12*Y

data = [(-1.5, .5, -6, -6),
 (1, -1, -46, 46),
 (-3, -1, 11, -11),
 (1, 1.5, 80, 80),
 (0.5, 0.25, 25, 15),
 (-1.5, -0.5, -5, 40)]

data = np.array(data, dtype=[('x', np.float32), ('y', np.float32),
 ('u', np.float32), ('v', np.float32)])

#Default parameters, uniform grid
ax = plt.subplot(2,2,1)
ax.barbs(X, Y, -U, -V)

#Arbitrary set of vectors, make them longer and change the pivot point
#(point around which they're rotated) to be the middle
ax = plt.subplot(2,2,2)
ax.barbs(data['x'], data['y'], data['u'], data['v'], length=8,  
pivot='middle')

#Showing colormapping with uniform grid.  Fill the circle for an  
empty barb,
#don't round the values, and change some of the size parameters
ax = plt.subplot(2,2,3)
ax.barbs(X, Y, U, V, np.sqrt(U*U + V*V), fill_empty=True,  
rounding=False,
 sizes=dict(emptybarb=0.25, spacing=0.2, height=0.3))

#Change colors as well as the increments for parts of the barbs
ax = plt.subplot(2,2,4)
ax.barbs(data['x'], data['y'], data['u'], data['v'], flagcolor='r',
 barbcolor=['b','g'], barb_increments=dict(half=10, full=20,  
flag=100),
 flip_barb=True)

plt.show()


--
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Extending a plot outside of axes

2009-01-19 Thread Jeff Whitaker
Einar M. Einarsson wrote:
 Hi all.

 is it not possible to extend plot outside of a plot area? To  
 illustrate what I want
 to do take for example the wind barbs example from the matplotlib  
 gallery.
 (see below)

 I only changed line 23 from ax.barbs(X, Y, U, V) to ax.barbs(X, Y, - 
 U, -V)

 But now we don't see the tail of the barbs in the first subplot.

 So Is it possible to let matplotlib plot the tail, without extending  
 the axes?
   

Einar:  You can use the set_clip_box method of the barbs instance to 
turn clipping off:

bb = ax.barbs(X, Y, -U, -V)
bb.set_clip_box(None)

-Jeff
 Best Regards
 Einar M. Einarsson

 '''
 Demonstration of wind barb plots
 '''
 import matplotlib.pyplot as plt
 import numpy as np

 x = np.linspace(-5, 5, 5)
 X,Y = np.meshgrid(x, x)
 U, V = 12*X, 12*Y

 data = [(-1.5, .5, -6, -6),
  (1, -1, -46, 46),
  (-3, -1, 11, -11),
  (1, 1.5, 80, 80),
  (0.5, 0.25, 25, 15),
  (-1.5, -0.5, -5, 40)]

 data = np.array(data, dtype=[('x', np.float32), ('y', np.float32),
  ('u', np.float32), ('v', np.float32)])

 #Default parameters, uniform grid
 ax = plt.subplot(2,2,1)
 ax.barbs(X, Y, -U, -V)

 #Arbitrary set of vectors, make them longer and change the pivot point
 #(point around which they're rotated) to be the middle
 ax = plt.subplot(2,2,2)
 ax.barbs(data['x'], data['y'], data['u'], data['v'], length=8,  
 pivot='middle')

 #Showing colormapping with uniform grid.  Fill the circle for an  
 empty barb,
 #don't round the values, and change some of the size parameters
 ax = plt.subplot(2,2,3)
 ax.barbs(X, Y, U, V, np.sqrt(U*U + V*V), fill_empty=True,  
 rounding=False,
  sizes=dict(emptybarb=0.25, spacing=0.2, height=0.3))

 #Change colors as well as the increments for parts of the barbs
 ax = plt.subplot(2,2,4)
 ax.barbs(data['x'], data['y'], data['u'], data['v'], flagcolor='r',
  barbcolor=['b','g'], barb_increments=dict(half=10, full=20,  
 flag=100),
  flip_barb=True)

 plt.show()


   



--
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] HTML area for a matplotlib picture

2009-01-19 Thread Romain Bignon
Hello,

This code worked with matplotlib 0.87:

fig = Figure()
ax = fig.add_subplot(121)
width = 0.5 # the width of the bars
self.dpi = 70
yoff = array([0.0] * len(self.__labels)) # the bottom values for stacked 
bar chart

self.__bars = ()
for row in xrange(rows):
self.__bars += (ax.bar(ind, self.__data[row], width, bottom=yoff, 
color=colours),)
yoff = yoff + self.__data[row]

#...
fig.set_size_inches(self.size[0], self.size[1])
imdata=StringIO()
fig.savefig(imdata,format='png', dpi=self.dpi)
self.__image = imdata.getvalue()
self.height = fig.get_figheight()* self.dpi
#...
coords = []

for bar in self.__bars:
x1 = []
y1 = []
x2 = []
y2 = []
# For each bars, we get values of rectangles
for b in bar:
x1 += [b.get_x(),]
y1 += [b.get_y(),]
if matplotlib.compare_versions(matplotlib.__version__, '0.97'):
x2 += [b.get_x() + b.get_width(),]
y2 += [b.get_y() + b.get_height(),]
else:
x2 += [b.get_x() + b.width,]
y2 += [b.get_y() + b.height,]

if matplotlib.compare_versions(matplotlib.__version__, '0.97'):
xys1 = zip(x1, y1)
xys2 = zip(x2, y2)
# We get the top left points for each bars...
xys1 = bar[0].get_transform().transform(xys1)
# ...and the bottom right points for each bars.
xys2 = bar[0].get_transform().transform(xys2)
else:
xys1 = zip(bar[0].get_transform().seq_x_y(x1, y1))
xys2 = zip(bar[0].get_transform().seq_x_y(x2, y2))

# Now for each bars, we can make a (x,y,w,h) data coords for HTML map 
area.
for (sx1, sy1), (sx2, sy2) in zip(xys1, xys2):
coords.append(sx1, self.height - sy2, sx2, self.height))
#...then coords is used to build the html area tags

Where it works with matplotlib 0.87, the behavior isn't correct with 
matplotlibĀ 0.98.

There are some version tests to run correctly compatible code. Blocks are
equivalents, but as the v0.87 code works, the v0.98 code doesn't produce the
same behavior.

For example, if xys1 and xys2 are:
xys1 = [(0.0, 0.0), (0.5, 0.0), (1.0, 0.0), (1.5, 0.0), (2.0, 0.0), (2.5, 0.0), 
(3.0, 0.0), (3.5, 0.0), (4.0, 0.0), (4.5, 0.0)]
xys2 = [(0.5, 992.0), (1.0, 1025.0), (1.5, 972.0), (2.0, 1004.0), (2.5, 
1007.0), (3.0, 1004.0), (3.5, 974.0), (4.0, 995.0), (4.5, 981.0), (5.0, 964.0)]

The arrays produced by the transform() methods will be:

xys1 = [[  50.20. ]
[  65.5   20. ]
[  81.20. ]
[  96.5   20. ]
[ 112.20. ]
[ 127.5   20. ]
[ 143.20. ]
[ 158.5   20. ]
[ 174.20. ]
[ 189.5   20. ]]
xys2 = [[  6.5500e+01   1.31228533e+05]
[  8.1000e+01   1.3559e+05]
[  9.6500e+01   1.28583200e+05]
[  1.1200e+02   1.32815733e+05]
[  1.2750e+02   1.33212533e+05]
[  1.4300e+02   1.32815733e+05]
[  1.5850e+02   1.28847733e+05]
[  1.7400e+02   1.31625333e+05]
[  1.8950e+02   1.29773600e+05]
[  2.0500e+02   1.27525067e+05]]

Firstly, the horizontal axe is separated with 15.5 points, but on picture, 28 
are needed.
Then, vertical values are around 1.0e+05, but self.height=175!

Is there any matplotlib behavior changed in new versions?

Thanks, regards

-- 
Romain Bignon -- http://romain.peerfuse.org

http://peerfuse.org


pgp5uo6Mn4iCs.pgp
Description: PGP signature
--
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] PS backend

2009-01-19 Thread Paul Novak

Hello,

I am having some problems with the PS backend. I used the following
script to create a PostScript file

#!/usr/bin/env python
import matplotlib
matplotlib.use('PS')
import matplotlib.pyplot as plt
import numpy

x1 = numpy.arange(0,5)
y1 = x1
plt.plot(x1, y1)
plt.savefig('ps_backend.ps')
plt.show()


When I tried to open the PostScript file in GSview, there is the
following warning, and the file does not render properly. I have
attached the PostScript file and a screenshot of the incorrect rendering.

DSC Error
At line 233:
   %%Page: 1 1
This %%Page: line occurred in the trailer, which is not legal.
EPS files should be encapsulated in %%BeginDocument / %%EndDocument.
If is possible that an EPS file was incorrectly encapsulated,
and that we have been confused by the %%Trailer in an EPS file.


The error can be eliminated by removing the line with %%EOF at line 230, 
but I don't know anything about PostScript or if that change would have 
any other effects. I only found this solution after comparing with the 
output from the Cairo backend. The same change to PostScript output can 
be achieved with the following diff (from svn diff), but again, I don't 
know if it is appropriate.


Index: ttconv/pprdrv_tt.cpp
===
--- ttconv/pprdrv_tt.cpp(revision 6810)
+++ ttconv/pprdrv_tt.cpp(working copy)
@@ -1070,7 +1070,6 @@
} /* end of if Type 42 not understood. */

 stream.putline(FontName currentdict end definefont pop);
-stream.putline(%%EOF);
 } /* end of ttfont_trailer() */

 /*--


Paul Novak



ps_backend.ps
Description: PostScript document
inline: incorrect_rendering.png--
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Two bugs in quiver?

2009-01-19 Thread George Nurser
I think there may be two bugs in quiver.

1. Quiver doesn't seem to accept 1D arrays X and Y if they are
different sizes -- they need to be turned into 2d arrays with meshgrid
for the program to work. With line 13 uncommented I get the following
error message:

  File quivtest.py, line 13, in module
ax.quiver(XT,YT,uu,vv) #fails
  File 
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py,
line 5533, in quiver
q = mquiver.Quiver(self, *args, **kw)
  File 
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/quiver.py,
line 343, in __init__
self.XY = np.hstack((X[:,np.newaxis], Y[:,np.newaxis]))
  File 
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/numpy/lib/shape_base.py,
line 488, in hstack
return _nx.concatenate(map(atleast_1d,tup),1)
ValueError: array dimensions must agree except for d_0

2. Masking is not working properly with quiver, while it works fine
with contour -- see the attached quivtest.png

quiver.py:

import numpy as np
import numpy.ma as ma
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
XT = np.arange(10.)
YT = np.arange(20.)
uu = np.zeros([20,10])+7.
vv = np.zeros([20,10])+3.

fig = plt.figure()
ax = fig.add_subplot(121)
# ax.quiver(XT,YT,uu,vv) #fails
XX,YY = np.meshgrid(XT,YT)
ax.quiver(XX,YY,uu,vv) #Ok

ax = fig.add_subplot(122)
msk = XX**2+YY**2 50
uumsk = ma.masked_array(uu,mask=msk)
vvmsk = ma.masked_array(vv,mask=msk)
ax.contour(XT,YT,uumsk*XX) # works
ax.quiver(XX,YY,uumsk,vvmsk) # gives strange shapes
plt.show()
fig.savefig('quivtest.png',dpi=100)

George Nurser.
attachment: quivtest.png--
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Strange problem with savefig?

2009-01-19 Thread George Nurser
I am finding a very strange error.

I have a program that integrates a partial differential equation using
fortran code in an f2py module. Data in arrays held in the f2py module
is updated in the fortran code. The module arrays are exposed to
python (but not changed by python code). After each increment of
timestep the array is plotted using matplotlib, and a figure saved
with savefig, so as to create an animation.

What I am finding is that the fortran module array is becoming
corrupted with NaNs.

If, however, I simply comment out the call to savefig in my python
code, there is no corruption of the module arrays.

WxAgg backend, Intel Mac OS 10.5.6, python 2.5.2, matplotlib svn
revision 6739, numpy 1.3.0.dev6297

I have the same problem with GtkAgg python 2.5.1 + matplotlib svn
6757.+ numpy 1.3.0.dev6297 on suse linux 10.1, amd_64.

George Nurser.



.

--
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Two bugs in quiver?

2009-01-19 Thread Eric Firing
George Nurser wrote:
 I think there may be two bugs in quiver.

Thanks for the report.  I can reproduce both problems, and I will try to 
solve them.

Eric

 
 1. Quiver doesn't seem to accept 1D arrays X and Y if they are
 different sizes -- they need to be turned into 2d arrays with meshgrid
 for the program to work. With line 13 uncommented I get the following
 error message:
 
   File quivtest.py, line 13, in module
 ax.quiver(XT,YT,uu,vv) #fails
   File 
 /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py,
 line 5533, in quiver
 q = mquiver.Quiver(self, *args, **kw)
   File 
 /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/quiver.py,
 line 343, in __init__
 self.XY = np.hstack((X[:,np.newaxis], Y[:,np.newaxis]))
   File 
 /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/numpy/lib/shape_base.py,
 line 488, in hstack
 return _nx.concatenate(map(atleast_1d,tup),1)
 ValueError: array dimensions must agree except for d_0
 
 2. Masking is not working properly with quiver, while it works fine
 with contour -- see the attached quivtest.png
 
 quiver.py:
 
 import numpy as np
 import numpy.ma as ma
 import matplotlib
 matplotlib.use('Agg')
 import matplotlib.pyplot as plt
 XT = np.arange(10.)
 YT = np.arange(20.)
 uu = np.zeros([20,10])+7.
 vv = np.zeros([20,10])+3.
 
 fig = plt.figure()
 ax = fig.add_subplot(121)
 # ax.quiver(XT,YT,uu,vv) #fails
 XX,YY = np.meshgrid(XT,YT)
 ax.quiver(XX,YY,uu,vv) #Ok
 
 ax = fig.add_subplot(122)
 msk = XX**2+YY**2 50
 uumsk = ma.masked_array(uu,mask=msk)
 vvmsk = ma.masked_array(vv,mask=msk)
 ax.contour(XT,YT,uumsk*XX) # works
 ax.quiver(XX,YY,uumsk,vvmsk) # gives strange shapes
 plt.show()
 fig.savefig('quivtest.png',dpi=100)
 
 George Nurser.
 
 
 
 
 
 
 
 --
 This SF.net email is sponsored by:
 SourcForge Community
 SourceForge wants to tell your story.
 http://p.sf.net/sfu/sf-spreadtheword
 
 
 
 
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] NOAA .bull file parsing

2009-01-19 Thread antonv

Hi Pierre,

Thanks for the quick and thorough response!
What I ended up doing is writing a custom function that does all the stuff
that I needed without using numpy or mlab. 

Anton


Pierre GM-2 wrote:
 
 Anton,
 You may wanna check on the numpy list as well.
 I recently reimplemented a function to read text file as a combination  
 of numpy.loadtxt and mlab.csv2rec, that handles missing data nicely.  
 You can get it here for the moment:
 https://code.launchpad.net/~pierregm/numpy/numpy_addons
 The function you would need is mafromtxt, in fromascii. Alternatively,  
 you can try using the scikits.timeseries package
 (http://pytseries.sourceforge.net/ 
 ): recent SVN versions introduced tsfromtxt, that read a text file and  
 return a timeseries.
 
 However, none of these possibilities will work out-of-the-box, because  
 of the presence of the footer. What you could do is write a first  
 function that gets rid of this footer (example of MO: open the file,  
 read all the lines in a list, get rid of the first 7 rows (header) and  
 last 8 ones, store the result in a file). Once you have only the data,  
 use mafromtxt (for example) using space as a delimiter, and specify  
 the columns you want to use with usecols (that way, you can get rid of  
 the column with the '*'). The missing data should be taken into  
 account properly.
 
 Let me know how it goes.
 P.
 
 
 
 On Jan 17, 2009, at 2:16 AM, antonv wrote:
 

 Dear all,

 I know this is not related to matplotlib but this seems to be the  
 only place
 where I found people that have knowledge of both NOAA data and  
 python so
 please bear with me.

 The .bull file that NOAA gives for upload is an ascii file formatted  
 for
 human readability but it creates a lot of issues when I am trying to  
 parse
 it. Here is a link to one of these files:

 ftp://ftpprd.ncep.noaa.gov/pub/data/nccf/com/wave/prod/wave.20090117/bulls.t00z/akw.46001.bull

 Do you have any idea on how to extract the data there in columns for
 plotting with matplotlib? If you look at the file you'll notice that  
 there
 is both a header and a footer for the file that needs to be  
 eliminated and
 the main columns have sub columns also. Another issue is that in a  
 column
 there is missing data that should keep it's relationship with the time
 column. And the last issue, some of the values there are preceded by  
 a *
 sign that should just be removed too.

 Any ideas are greatly appreciated!

 Anton

 -- 
 View this message in context:
 http://www.nabble.com/NOAA-.bull-file-parsing-tp21513800p21513800.html
 Sent from the matplotlib - users mailing list archive at Nabble.com.


 --
 This SF.net email is sponsored by:
 SourcForge Community
 SourceForge wants to tell your story.
 http://p.sf.net/sfu/sf-spreadtheword
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users
 
 
 --
 This SF.net email is sponsored by:
 SourcForge Community
 SourceForge wants to tell your story.
 http://p.sf.net/sfu/sf-spreadtheword
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users
 
 

-- 
View this message in context: 
http://www.nabble.com/NOAA-.bull-file-parsing-tp21513800p21554671.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


--
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Two bugs in quiver?

2009-01-19 Thread Eric Firing
George Nurser wrote:
 I think there may be two bugs in quiver.

Actually just 1...

 
 1. Quiver doesn't seem to accept 1D arrays X and Y if they are
 different sizes -- they need to be turned into 2d arrays with meshgrid
 for the program to work. With line 13 uncommented I get the following
 error message:

This is a bug.  It is fixed now in svn trunk and 98.5 maintenance branch.

 
 2. Masking is not working properly with quiver, while it works fine
 with contour -- see the attached quivtest.png

This is a numpy.ma bug that has been fixed in numpy.  I don't know 
exactly when it was fixed, but after I tracked it down to numpy.ma, I 
updated my copy of numpy from svn, and the problem went away.  Somehow, 
when a multiplication was done with broadcasting, the mask was getting 
handled and propagated incorrectly.  I suspect this bug was present only 
for a moderate interval of time, because quiver with masked points 
worked for a long time before you ran into the bug.

Eric

--
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] plot a data stream with matplotlib

2009-01-19 Thread Ryan May
Simone Gabbriellini wrote:
 I see that you first build your array and then display it at the end...
 
 is it possible in matplotlib to update the plot while the class is
 evolving? like:
 
 f.evolve(6)
 f.display()
 f.evolve(.27)
 f.display()
 f.evolve(10)
 f.display()
 f.evolve(2)
 f.display()

You'd want to look at the animation examples in examples/animation.  The exact
details will depend upon what backend you want to use, but strip_chart_demo.py,
simple_anim_gtk.py, and gtk_timeout.py are good places to start.

HTH,

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

--
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users