 # 1D heat map

Hi,

I have a code for making graphical representations of sentences, Sentence is
represented as a bar, and under in you can represent the words. It works
fine and I have an example at the end.

Now I wanted to add some more features to it, but I am stuck.
you can see the previous post from this link

Now, if we assign a number to each letter in a sentence and get a list of
these numbers,
[2,4,7,-7,8,6,4,4,-7,9,5,3,-7,9,5,-3,7,8,9,5,3,6,8,9,-5,3]
can I create a 1D heat map with this list as and additional bar?

First problem will be to get the range of numbers and normalize it, or we
should be able to assign a range for the heat map.

It would be great if you can help.

here is the example code.

[CODE]

text ='''World number two Nadal breezed through the first set, taking it
with breaks of serve in the fourth and sixth games.
Monfils put up more resistance in an erratic second set but his wayward
display was summed up by a double fault which sealed Nadal's victory.
The Spaniard will face a semi-final against compatriot Nicolas Almagro, who
beat Austrian Juergen Melzer 6-3 6-1.
In the women's competition, fourth seed Venus Williams booked her place in
the semi-finals with a 6-3 6-3 win over Australia's Samantha Stosur.'''
import pylab
import matplotlib

# Put text into list of sentences
sentences = []
sentences = text.split('\n')

# Get the lenght of longest sentence-Lmax and number of sentences
Lmax=0
it = 0
for i in sentences:
it = it + 1
LenSen= len(i)
if LenSen > Lmax:
Lmax = LenSen
totalnumber = it

#Set the image properties
pylab.rcParams['figure.figsize'] = [Lmax/20, totalnumber]
pylab.rcParams['figure.subplot.left'] = 0.2 # Left margin
pylab.rcParams['figure.subplot.right'] = 1.0-0.04 # Right margin
pylab.rcParams['font.size'] = 7

# Axes range from 0 to 1 for x-axis (simplifying calls to .axhspan()) and
# 20 down to 0 for Y-values because that's convenient for this example
ax = [0, 1, totalnumber+1, 0] # [xlo, xhi, ylo, yhi]

# printer is a drawing module
def printer(searchterm, Input,start,end,xstart,color):
lens = len(searchterm)
while True:
inDex = Input.find(searchterm, start,end)
if inDex == -1:
break
inDex = float(inDex)
inDS=inDex/Lmax
inDE=(inDex+lens)/Lmax
matplotlib.pyplot.axhspan(it+xstart,it+0.2+xstart, xmin=inDS,
xmax=inDE, ec='k', fc=color)
# search is complete, break out of the while loop

# move to next possible start position
inDex= int(inDex)
start = inDex + 1
it=0
for i in sentences:
it = it+1
LenSen= len(i)
LenF = float(LenSen)
matplotlib.pyplot.axhspan(it+0.2,it+0.4, xmin=0, xmax=LenF/Lmax,
ec='k', fc='r') #creates sentence bar
pylab.text(-0.2, it+0.4, 'sentence'+str(it)+' with spaces') # create
the sentence bar
printer(' ', i, 1, LenSen,0.2,'b') #blue represents the spaces on
sentence bar
printer('the', i, 1, LenSen,0,'y') #above sentence bar, yellow
represents 'the'
pylab.text(-0.2, it+0.2, 'the')

pylab.axis(ax)
matplotlib.pyplot.title("Analysis")

matplotlib.pyplot.xticks((),()) # No labels for X-axis
matplotlib.pyplot.yticks((),()) # No labels for Y-axis
pylab.show()

[CODE]

···

--
View this message in context: http://old.nabble.com/1D-heat-map-tp32374379p32374379.html
Sent from the matplotlib - users mailing list archive at Nabble.com.