Print dictionary using matplotlib

0

Hello,

I have a dictionary of type: and I would like to print a line chart with the key k as x and v as y.

I tried a number of things but kept getting errors:

plt.plot(lr.keys(),lr.values())
plt.title('ID modelo:'+str(Index)+' model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.savefig('ID modelo:'+str(Index)+' model accuracy.png')
plt.clf()

TypeError: float () argument must be a string or a number, not 'dict_keys'

    
asked by anonymous 15.04.2017 / 22:54

1 answer

0

In a dictionary, when you only ask for .keys() or .values() it gives the answer along with dict_keys or dict_values .

This is what is happening there in your code, the type number float is coming along with this dict that is giving this error.

That's what I think, by looking at what you put in the question. If you can put more things so we can see better.

See, example:

dic = {'teste':'teste2'}

>>> print(dic.keys())
>>> dict_keys(['teste']) #Resultado, com dict
>>>
>>> print(dic.values())
>>> dict_values(['teste2']) #Resultado, com dict

To resolve:

>>> print(list(dic.keys()))
>>> ['teste'] #Resultado, sem dict
>>>
>>> print(list(dic.values()))
>>> ['teste2'] #Resultado, sem dict

try adapting to your code.

    
16.04.2017 / 01:05