Re: [Matplotlib-users] windrose 0.5

2007-02-01 Thread Lionel Roubeyrie
Hi Derek,
I forgot to mention: you can pass throught your problem by using a masked 
array instead of a simple array, and it should work fine, the 'default' 
parameter is here to fill missing value by -1.e20, then these directions will 
be dropped if your speed_classes not include that missing value (generally we 
compute on positives speeds).

Le Jeudi 01 Février 2007 13:17, Derek Hohls a écrit :
 Lionel

 I have encountered a problem with windrose.  In some cases, one or more
 of the
 wind direction values are null [''] - the program then fails on line
 200:
values = select( [greater_equal( direction, wind_classes[i]
 )],[speed], default=-1.e20 )
 Is it possible for you to upgrade the program to perform error
 trapping
 and simply skip (i.e. not process) any values that are null (and handle
 the
 exceptional case that all of them might, in fact, be null).

 Thanks!
 Derek


-- 
Lionel Roubeyrie - [EMAIL PROTECTED]
LIMAIR
http://www.limair.asso.fr


-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Wrong colorbar-ticks in imshow-colorbar with 10 colors

2007-02-01 Thread Claas Teichmann

Hi all,

I want to use imshow to plot an array of floats using
interpolation='nearest' so that every gridbox has a distinct color. Also I
want to limit the number of colors to a rather small number, e.g. 10. The
problem is that the tick labels are not at the edge of each color in the
colorbar, but somewhere in between.

An example is the trunk/matplotlib/examples/poormans_contour.py which does
not work in my case.

from pylab import *


delta = 0.01
x = arange(-3.0, 3.0, delta)
y = arange(-3.0, 3.0, delta)
X,Y = meshgrid(x, y)
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = Z2 - Z1 # difference of Gaussians

cmap = cm.get_cmap('jet', 10)# 10 discrete colors

im = imshow(Z, cmap=cmap, interpolation='bilinear')
axis('off')
colorbar()
#savefig('test')
show()

Is there a solution?


Ciao Claas
-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Bug: Image transparency varies periodically for imshow(img, aspect='auto') at high magnification

2007-02-01 Thread Joel Hedlund

Hi!

I believe I've found a bug in matplotlib which manifests after 
imshow(img, aspect='auto') when only a small portion of the image is 
displayed, e.g: when (xmax-xmin)  img.shape[1]. The effect of the bug 
is that the transparency for the entire image seems to vary, seemingly 
as a periodic funtion of (xmax-xmin). Explicitly setting the alpha 
channel for each pixel has no effect.


The attached script generates a random image of a certain size, and 
plots it in four different subplots. The only thing that differs between 
the subplots are slight variations in x_max. The four subplots are labeled:


1) The background image is visible.
2) The background image is not visible!
3) The background image is faded!
4) The background image is again visible!

which reflects the actual result on my system. As the subplots are 
scaled (for example by resizing the window), the intensity then varies 
in a periodic manner in each of the subplots.


The expected result is of course that the background should be fully 
visible in all subplots.


Additional details:

$ python test.py --verbose-helpful
matplotlib data path /usr/lib/python2.4/site-packages/matplotlib/mpl-data
$HOME=/home/bioinfo/yohell
CONFIGDIR=/home/bioinfo/yohell/.matplotlib
loaded rc file 
/usr/lib/python2.4/site-packages/matplotlib/mpl-data/matplotlibrc

matplotlib version 0.87.7
verbose.level helpful
interactive is False
platform is linux2
numerix numpy 1.0
font search path ['/usr/lib/python2.4/site-packages/matplotlib/mpl-data']
loaded ttfcache file /home/bioinfo/yohell/.matplotlib/ttffont.cache
backend WXAgg version 2.6.1.2pre

In this example I used the WXAgg backend, but GTKAgg shows the same 
results. I've also reproduced this bug on a WinXP machine.


Thanks for an excellent plotting package!
/Joel Hedlund
Linköping University
import numpy, pylab
image = numpy.random.randint(0, 255, 309 * 1230 * 3)
image.shape = (309, 1230, 3)
pylab.subplot(221)
pylab.text(72.5, 200, 'The background image\nis visible.')
pylab.imshow(image, aspect='auto')
pylab.axis((72, 75, 0, 309))
pylab.subplot(222)
pylab.imshow(image, aspect='auto')
pylab.text(72.5, 200, 'The background image\nis not visible!')
pylab.axis((72, 76, 0, 309))
pylab.subplot(223)
pylab.imshow(image, aspect='auto')
pylab.text(72.5, 200, 'The background image\nis faded!')
pylab.axis((72, 77, 0, 309))
pylab.subplot(224)
pylab.imshow(image, aspect='auto')
pylab.text(72.5, 200, 'The background image\nis again visible!')
pylab.axis((72, 78, 0, 309))
pylab.show()
-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Bug: Image transparency varies periodically for imshow(img, aspect='auto') at high magnification

2007-02-01 Thread Darren Dale
Hi Joel,

On Thursday 01 February 2007 11:09:11 am Joel Hedlund wrote:
 I believe I've found a bug in matplotlib which manifests after
 imshow(img, aspect='auto') when only a small portion of the image is
 displayed, e.g: when (xmax-xmin)  img.shape[1]. The effect of the bug
 is that the transparency for the entire image seems to vary, seemingly
 as a periodic funtion of (xmax-xmin). Explicitly setting the alpha
 channel for each pixel has no effect.

 The attached script generates a random image of a certain size, and
 plots it in four different subplots. The only thing that differs between
 the subplots are slight variations in x_max. The four subplots are labeled:

 1) The background image is visible.
 2) The background image is not visible!
 3) The background image is faded!
 4) The background image is again visible!

 which reflects the actual result on my system. As the subplots are
 scaled (for example by resizing the window), the intensity then varies
 in a periodic manner in each of the subplots.

 The expected result is of course that the background should be fully
 visible in all subplots.

I can verify this behavior, more or less. I observe that the figure.dpi rc 
setting influences the results (I tried 86.23 and 200).

-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Help needed: Rendering of multiple text labels is very slow.

2007-02-01 Thread Joel Hedlund

Hi!

I'm using matplotlib and pygtk to write a viewer for multiple sequence 
alignments. (Big matrices (~100x1000) of characters, usually colored by 
cell according to chemical properties). Now I've run into trouble since 
the rendering of the actual characters is very slow. I have included a 
small example that illustrates this. Set SHOW_LETTERS = False to see the 
change in rendering speed. The difference is even greater when using 
real data, so I would very much appreciate suggestions as to how I could 
improve it.


My strategy:
I create an image with the same dimension as the msa, and where each 
pixel is colored according to properties of the corresponding character 
in the msa. I plot this in the background of the figure using imshow(). 
At each redraw (refresh, resize, zoom...) I determine the size that each 
image pixel occupies at the current canvas size, and pick a font where 
one letter will fit inside this square. Then I put the corresponding msa 
 letter into this square using text()/add_artist().


Would it be possible to use only one Text instance that would hold all 
letters, and somehow stretch that to the desired size? If so, could I 
expect better performance?


Does anyone have a better idea?

Thanks for an awesome plotting package!
/Joel Hedlund
# Change this to see change in rendering speed:
SHOW_LETTERS = False

import matplotlib
matplotlib.use('GTKAgg')
import pylab
from numpy import array, uint8

RED = array([229, 51, 25], uint8)
BLUE = array([25, 127, 229], uint8)
GREEN = array([25, 204, 25], uint8)
CYAN = array([25, 178, 178], uint8)
PINK = array([229, 127, 127], uint8)
MAGENTA = array([204, 76, 204], uint8)
YELLOW = array([204, 204, 0], uint8)
ORANGE = array([229, 153, 76], uint8)
WHITE = array([255, 255, 255], uint8)
colors = {'G': ORANGE,
  'P': YELLOW,
  'T': GREEN,
  'S': GREEN,
  'N': GREEN,
  'Q': GREEN,
  'W': BLUE,
  'L': BLUE,
  'V': BLUE,
  'I': BLUE,
  'M': BLUE,
  'A': BLUE,
  'F': BLUE,
  'C': BLUE,
  'H': CYAN,
  'Y': CYAN,
  'E': MAGENTA,
  'D': MAGENTA,
  'K': RED,
  'R': RED}

msa = \
KYFALQ---
KYFALQPDDVYYCGIKYIKDDVILNEPSAD---APAALY--QTIEENIKIFVEFISVPVPE
KYFALQPDDVYYCGIKYIKDDVLLNEPSAD---APAARY--QTIEENIKIFEEDEVEFISVPVPE
KYFAFQPDDVYYCGIKYIKDDVVLNEPSAD---APASRY--QTIEENIKIFEEDEVEFISVPVPE
KYFAFQQDDVYYCGIKYIKDDLILNEPSAN---APAARF--QTIEENIKILEEDNVEFISVPVPE
KYFAMQ-RGVYFCGIRYLEDDAALTEPYAETPVRY--HSFRESIQILVELINVPVPE
KYFAMQ-RGVYFCGIRYLEDDAALTEPYAETPVRY--HSFKESIQILEEEDVELINVPVPE
KYFAMQ-RGVYFCGIRYLEDDAALTEPYAETPVRY--HSFKESIQILEEEDVELINVPVPE
KYFAFQ-GGVYFCGIKYIEDGLSLPESGAE---AQSARY--HTIEQNIQILEEEDVEFISVPVPE
KYFAFQQGGVYFCGIKYIEDGLSLPESGAQ---LKSARY--HTIEQNIQILEEEDVEFISVPVPE
RYYVLERDQVFICGLKYYEEDYELNEEVDP-EIGAPLRLIEENVSFFEDDEVELISVPVPE
HHYYNPEVSYQHHGGWED-EVELPNQFPLRQMEERIRVLEREQVELISVPVPE
RYYFIEEERMYFCGVNYREENYKMQDSQEDTDMDLPAAY--KRIEEKVRVLEDEGVELINIPVPK
.splitlines(False)

tmp = []
for s in msa:
tmp.extend(colors.get(t, WHITE) for t in s)
bg = array(tmp)
bg.shape = (len(msa), len(msa[0]), 3)

class CharSize(object):
def __init__(self, width=None, height=None, fontprops=None):
self.width = width
self.height = height
self.fontprops = fontprops

def __lt__(self, other):
if not isinstance(other, tuple):
raise TypeError(can only be compared to (x, y) tuple)
return (self.width  other[0] * 0.5) and (self.height  other[1] * 0.5)

class FontSelector(object):
def __init__(self, charsizes=None):
if charsizes is None:
charsizes = []
self.charsizes = charsizes

@classmethod
def from_sizes(cls, renderer, *fontsizes, **fontprops):
if not fontsizes:
raise TypeError(need a font size range)
o = cls()
for i in sorted(range(*fontsizes), reverse=True):
fontprops['size'] = i
oFontProps = matplotlib.font_manager.FontProperties(**fontprops)
nWidth, nHeight = renderer.get_text_width_height('M', oFontProps, 
False)
o.charsizes.append(CharSize(nWidth, nHeight, oFontProps))
return o

def by_cell_size(self, width, height):
tnAvailableSize = (width, height)
for oCharSize in self.charsizes:
if oCharSize  tnAvailableSize:
return oCharSize.fontprops
return None

figure = pylab.figure()
renderer = figure.canvas.get_renderer()
font_selector = FontSelector.from_sizes(renderer, 4, 18, family='monospace')

def replot(widget):
pylab.cla()
pylab.imshow(bg, origin='lower', interpolation='nearest', aspect='auto')
pylab.ylim(len(msa), 0)
iWidth, iHeight = figure.canvas.get_width_height()
nCharWidth = iWidth / float(len(msa[0]))
nCharHeight = iHeight / float(len(msa))
oFont =