[Matplotlib-users] query on weighted matrix example

2011-09-26 Thread Bala subramanian
Friends,
In the mpl site, i found the an example code called hinton_demo to plot
weighted matrix in the following link.

http://matplotlib.sourceforge.net/examples/api/hinton_demo.html?highlight=hinton

I used the same script (attached test.py) making a slight modification in
the following section of the code pasted below. I just included more color
range and modified the size as np.sqrt(np.abs(w))/5.

However when i run the script with test data (attached test.dat), i found
that the size of the square and color are not matching. For instance the
size of the squares at position 4,3 and 7,6 are small but the color (black)
is not relevant to the size. I am not getting what is going wrong. Kindly
help to resolve the problem.

The script and test data are attached.

*Section of the code modified*

for (x,y),w in np.ndenumerate(W):
if w > 0: color = 'white'
else: color = 'black'
size = np.sqrt(np.abs(w))
rect = Rectangle([x - size / 2, y - size / 2], size, size,
facecolor=color, edgecolor=color)
ax.add_patch(rect)
#!/usr/bin/env python   
#Initial idea from David Warde-Farley on the SciPy Cookbook
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from matplotlib.ticker import NullLocator
import matplotlib as mpl
from sys import argv
# This script was extraced from mpl website.
mpl.rcParams['font.size']=7
mpl.rcParams['font.family']='bold'


mat=np.loadtxt(argv[1])

def hinton(W, maxWeight=None, ax=None):
"""
Draws a Hinton diagram for visualizing a weight matrix.
"""
if not ax:
fig = plt.figure(figsize=(3.60,3.60),dpi=300)
ax = fig.add_subplot(1, 1, 1)

if not maxWeight:
maxWeight = 2**np.ceil(np.log(np.abs(W).max())/np.log(2))

ax.patch.set_facecolor('white')   
ax.set_aspect('equal', 'box')
ax.xaxis.set_major_locator(NullLocator())
ax.yaxis.set_major_locator(NullLocator())

for (x,y),w in np.ndenumerate(W):
if   w < 2.0: color = 'red'
elif 2.1 < w < 4.0: color='blue'
elif 4.1 < w < 6.0: color='green'
else: color = 'black'


size = np.sqrt(np.abs(w))/5 
rect = Rectangle([x - size / 2, y - size / 2], size, size,facecolor=color, edgecolor=color)

ax.add_patch(rect)
ax.autoscale_view()

# Reverse the yaxis limits
ax.set_ylim(*ax.get_ylim()[::-1])


hinton(mat)
plt.xticks(np.arange(0,9,1)) 
plt.yticks(np.arange(0,9,1)) 
plt.ylim([-0.5,8.5])
plt.xlim([-0.5,8.5])
plt.savefig('test.png',dpi=300,bbox_inches='tight')
#plt.show()


test.dat
Description: Netscape Proxy Auto Config
--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] How to plot heatmap with matplotlib?

2011-09-26 Thread Angus McMorland
On 25 September 2011 06:59, fdu.xia...@gmail.com  wrote:
> Dear all,
>
> Heatmap (like those on the page
> http://www2.warwick.ac.uk/fac/sci/moac/students/peter_cock/r/heatmap/)
> is a frequently used type of image in microarray data analysis. However,
> it seems there are no convenient functions in matplotlib to plot heatmap
> (please correct me if I was wrong), so I'm planning to write my own.
>
> Let me take the heatmap by the link
> http://www2.warwick.ac.uk/fac/sci/moac/students/peter_cock/r/heatmap/scaled_color_key.png
> as an example, which is produced by R.
>
> With my limited knowledge and expertise of matplotlib, I have the
> following questions and I hope you guys could help me.
>
> 1) I tend to use pcolor to draw the colormap in the central area.
> However, I've seen a lot of examples draw colormap with imshow.
>
>     What's the difference between pcolor and imshow?
>     Shall I use pcolor or imshow to produce the heatmap in the link above?

One difference between pcolor and imshow is that pcolor lines up the
bottom-left corner of each square with the co-ordinates given, whereas
imshow puts the grid center at those co-ordinates. My guess would be
(not having implemented a heatmap) that pcolor would be the more
useful to you to try first for this reason.

> 2) How to draw the dendrograms on the top and left of the colormap?
>
>     I got hints from
> http://matplotlib.sourceforge.net/examples/axes_grid/scatter_hist.html
> on how to append axes to current plot, but I still have now idea how to
> draw the dengrograms.

A quick google search suggests that scipy-cluster might help you out
with the dendrogram drawing. I think I would try using separate axes
objects for the heatmap and the dendrograms, and switch off the frames
of the dendrogram axes.

> 3) How to draw the column side colormap (the smaller one) between the
> top dendrogram and the big colormap?

This could another axes object too. You can use the sharex keyword to
add_axes to get it to have the same x scale as the big axes.

> 4) I can use colorbar to draw a colorbar, but how to place the colorbar
> on the topleft of the image just as the R heatmap does?

Again, the answer is to manually create the axes for your colorbar,
and then specify those axes in the call to colorbar using the `cax`
keyword.

> 5) Any other suggestions on how to draw the heatmap?

I suggest that you give it a try and post your efforts here if there
are any problems. We'll also be keen to see the final result, if you'd
like to share it.

I hope that helps at least a little. Happy coding,

Angus
-- 
AJC McMorland
Post-doctoral research fellow
Neurobiology, University of Pittsburgh

--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] contrast image

2011-09-26 Thread getnut

Hi,
   I try to apply contrast to an image with set_cmap() like it's explained
in this page  http://matplotlib.sourceforge.net/users/image_tutorial.html
http://matplotlib.sourceforge.net/users/image_tutorial.html  but when I
apply a new pseudocolor nothing appends. Please help me! This is my code.

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import matplotlib.cm as cm
import numpy as np
import sys

turno=0
pixel=0
img16=open(sys.argv[1],'r')
r=img16.read(2)
val=[]
i=0
riga=[]
while r !="":
if (pixel>=0) & (pixel<510):
r1=ord(r[0])
r2=(ord(r[1])&15)<<8
ris=(float(r1|r2))/4095
riga.append([ris,ris,ris])
else:
if pixel==511:
val.append(riga)
riga=[]
pixel=(pixel+1)%512
r=img16.read(2)
#for i in range(512):
#   print len(val[i])
#   print val[i]
val=np.array(val,dtype=np.float32)
imgplot = plt.imshow(val)
imgplot.set_cmap(cm.binary)
plt.show()
-- 
View this message in context: 
http://old.nabble.com/contrast-image-tp32503930p32503930.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] query on weighted matrix example

2011-09-26 Thread Bala subramanian
Friends,
I have solved the problem by myself. I  gave
if w < 2.0: color = 'red'
if 2.1 < w > 4.0: color='blue' So wherever the value there is a value like
2.03 or 2.05, the color was shown as black instead of red/blue.

Thanks,
Bala

On Mon, Sep 26, 2011 at 9:25 AM, Bala subramanian  wrote:

> Friends,
> In the mpl site, i found the an example code called hinton_demo to plot
> weighted matrix in the following link.
>
>
> http://matplotlib.sourceforge.net/examples/api/hinton_demo.html?highlight=hinton
>
> I used the same script (attached test.py) making a slight modification in
> the following section of the code pasted below. I just included more color
> range and modified the size as np.sqrt(np.abs(w))/5.
>
> However when i run the script with test data (attached test.dat), i found
> that the size of the square and color are not matching. For instance the
> size of the squares at position 4,3 and 7,6 are small but the color (black)
> is not relevant to the size. I am not getting what is going wrong. Kindly
> help to resolve the problem.
>
> The script and test data are attached.
>
> *Section of the code modified*
>
> for (x,y),w in np.ndenumerate(W):
> if w > 0: color = 'white'
> else: color = 'black'
> size = np.sqrt(np.abs(w))
> rect = Rectangle([x - size / 2, y - size / 2], size, size,
> facecolor=color, edgecolor=color)
> ax.add_patch(rect)
>
>
--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Assign colors to list?

2011-09-26 Thread Katie Boyle
Hi All,

I was wondering how I take a list of 250 discrete values and match up each
value in the list to a color in the gist_rainbow colormap. I want the
highest value to be red, and the lowest value to be blue. I then want to
plot a point for each value in the list, and the point's color should
represent its value. I cannot use contourf or any other function that does
this automatically on a continuous grid--I need to plot individual points.

I have tried creating my own colormap with:

my_colors = matplotlib.colors.Colormap(my_list)

but when I issue a pyplot.plot() command with the argument cmap=my_colors, I
get "TypeError: There is no patch property "cmap"

How do I do this correctly?

Cheers,
Katie
--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Assign colors to list?

2011-09-26 Thread John Hunter
On Mon, Sep 26, 2011 at 12:05 PM, Katie Boyle  wrote:
> Hi All,
>
> I was wondering how I take a list of 250 discrete values and match up each
> value in the list to a color in the gist_rainbow colormap. I want the
> highest value to be red, and the lowest value to be blue. I then want to
> plot a point for each value in the list, and the point's color should
> represent its value. I cannot use contourf or any other function that does
> this automatically on a continuous grid--I need to plot individual points.

I think you are looking for "scatter", with the "c" argument being
your intensity value.  You can pass the gist_rainbow colormap to the
scatter function via the cmap argument.  See these examples

http://matplotlib.sourceforge.net/examples/pylab_examples/scatter_demo.html
http://matplotlib.sourceforge.net/examples/pylab_examples/scatter_demo2.html

--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Assign colors to list?

2011-09-26 Thread John Hunter
On Mon, Sep 26, 2011 at 12:24 PM, John Hunter  wrote:
> On Mon, Sep 26, 2011 at 12:05 PM, Katie Boyle  wrote:
>> Hi All,
>>
>> I was wondering how I take a list of 250 discrete values and match up each
>> value in the list to a color in the gist_rainbow colormap. I want the
>> highest value to be red, and the lowest value to be blue. I then want to
>> plot a point for each value in the list, and the point's color should
>> represent its value. I cannot use contourf or any other function that does
>> this automatically on a continuous grid--I need to plot individual points.
>
> I think you are looking for "scatter", with the "c" argument being
> your intensity value.  You can pass the gist_rainbow colormap to the
> scatter function via the cmap argument.  See these examples
>
> http://matplotlib.sourceforge.net/examples/pylab_examples/scatter_demo.html
> http://matplotlib.sourceforge.net/examples/pylab_examples/scatter_demo2.html

Eg,


In [43]: x, y, c = np.random.randn(3, 100)

In [44]: plt.scatter(x, y, c=c, cmap='gist_rainbow')
Out[44]: 

--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] matplotlib - fill open path inside U.S. borders

2011-09-26 Thread Isidora
Hi,
I am trying to plot filled paths over a U.S. map.  I plot the given paths, but 
since these are not closed paths, the filling is truncated at a line drawn 
between last and first point in the path.  I want to extend the path to the 
United States border instead.  


I am no expert in matplotlib or GIS.  Could anyone help me find documentation 
or blogs discussing this type of issue? I am convinced somebody else has 
already faced this problem although I have not been able to find any paper, 
documentation, blog on it. 

Thank you


--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] matplotlib 0.99.3 --> 1.0.1 plotting error

2011-09-26 Thread Andre' Walker-Loud
Hi All,

I recently upgraded my python packages through Enthought.

I have a mac osx 10.6.8

Previous versions: python 2.6, matplotlib 0.99.3 (Enthought 6.2)
New versions: python 2.7, matplotlib 1.0.1 (Enthought 7.1)

I am using the macosx backend.

I have some functions I wrote which analyze data.  They previously worked with 
no error.  Now I get a weird error I am not sure how to sort out yet:

Python[47092] : CGContextClosePath: no current point.

I believe this is a matplotlib issue as searching for CGContextClosePath 
returns errors regarding drawing lines.

I should add that my scripts still run, and the plots are still drawn, but I 
get a dump of error messages like this in my output.


Any ideas what is going on?


Thanks,

Andre




--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users