我正在尝试为该图绘制一条最合适的线。因为x是一个分类变量,所以我遇到了麻烦,如果其中一个是分类变量,我发现的所有解决方案都将不起作用。
这是我的剧情代码-
plt.title('Timeline of cases in Maharashtra')
plt.scatter(maharashtra_confirmed['Date'], maharashtra_confirmed['Maharashtra'], label = 'Maharashtra', color = 'orange')
plt.xticks(rotation = 90)
ax = plt.axes()
ax.xaxis.set_major_locator(ticker.MultipleLocator(2))
plt.legend()
plt.show()
答案 0 :(得分:0)
对于分类变量,从理论角度看,拟合没有意义。但是,您这里拥有的不是本质上的分类数据,而是(据我从您的输入中可以猜测到的)只是不能自动解释为非分类的数据。
因此,您必须将日期转换成更适当的表示形式。 datetime.datetime.strptime应该会在这里为您提供帮助。