Search code examples
pythondictionarymatplotlibplotvalueerror

ValueError: Unrecognized character a in format string


I have this data set that outputs strange error when I try to call its values. Unsure about where I am going wrong. where data1 is the dictionary, it outputs the following error:

~\anaconda3\lib\site-packages\matplotlib\axes\_base.py in _plot_args(self, tup, kwargs)
    310     def _plot_args(self, tup, kwargs):
    311         if len(tup) > 1 and isinstance(tup[-1], str):
--> 312             linestyle, marker, color = _process_plot_format(tup[-1])
    313             tup = tup[:-1]
    314         elif len(tup) == 3:

~\anaconda3\lib\site-packages\matplotlib\axes\_base.py in _process_plot_format(fmt)
    102             i += 2
    103         else:
--> 104             raise ValueError(
    105                 'Unrecognized character %c in format string' % c)
    106 

ValueError: Unrecognized character a in format string


I have extracted the type of both the dictionary and both value sets. The dictionary is a dict and the value sets for both are lists.

However, when I plot it the following way, it works:

plt.figure()
x= data1['date']
y = data1['value']
plt.plot(x,y)

What could be going wrong?


Solution

  • from matplotlib import pyplot as plt
        
    d = { "name" : ["Joe", "Maria", "Anna", "Bob"], "gender" : ["Male", "Female", "Female", "Male"], "salary" :[10000,20000,24000,14000]}
     
    plt.plot("name", "salary", data=d)
    plt.show()
    

    You have to pass in the parameter object so it can understand that you want the labels from the object. In your case it treat the "date", "value" as iterables because string is an iterable and it tries to set ticks "d", "a", "t", "e".