query on weighted matrix example

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)

test.py (1.52 KB)

test.dat (504 Bytes)

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 <bala.biophysics@…287…> 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)