lundi 20 avril 2015

Plotting strings vs floats (occurrence of letter codes vs percent composition)

I have a dataset of sequences (long strings of one-letter codes, e.g. "ACDEF ....", for which I have computed the mean occurrence of each letter over a couple thousand sequences. I would like to plot the mean percentage composition of each letter, using the following code:

import numpy as np
import matplotlib.pyplot as plt

res=[] 
freq=[]

for i in codes.values():
    res.append(i)
    freq.append(fraction_composition(i))    
res=np.array(res)
freq=np.array(freq)
freq*=100 

p1=plt.plot(res,freq,'r^--')

The codes.values() refers to the fact that each one letter code is actually part of a key-value pair stored in a dictionary, and I am simply calling a function iteratively so that the mean frequency of each letter is computed. I get the error message:

ValueError: could not convert string to float: C

after calling the plot function. How can this be resolved?

Many thanks

Aucun commentaire:

Enregistrer un commentaire