Python ValueError:格式字符串中无法识别的字符

Python ValueError:格式字符串中无法识别的字符,python,dictionary,matplotlib,plot,valueerror,Python,Dictionary,Matplotlib,Plot,Valueerror,我有一个数据集,当我试图调用它的值时,它会输出奇怪的错误。不确定我会错在哪里。 其中data1是字典,它输出以下错误: ~\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[-

我有一个数据集,当我试图调用它的值时,它会输出奇怪的错误。不确定我会错在哪里。 其中data1是字典,它输出以下错误:

~\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


我提取了字典和两个值集的类型。字典是一个dict,两者的值集都是列表

但是,当我以以下方式绘制它时,它是有效的:

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

可能出现什么问题?

您应该传递变量:

plt.plot(date,value,data1)

您必须传入参数对象,以便它能够理解您想要对象中的标签。在您的例子中,它将
“日期”、“值”
视为iterbles。因为
string
是一个
iterble
并且它试图设置记号“d”、“a”、“t”、“e”。

当我尝试此操作时,我获得了名称错误:名称“date”未定义。根据这篇文档:如果它是一个可调用的对象,比如字典,我应该能够以plt.plot('date','value',data1)的形式来做
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()