在x轴上绘制非数字数据(例如日期) [英] Plot with non-numerical data on x axis (for ex., dates)

查看:89
本文介绍了在x轴上绘制非数字数据(例如日期)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想针对非数字数据绘制数字数据,就像这样:

I'd like to plot numerical data against non numerical data, say something like this:

import matplotlib.pyplot as pl
x=['a','b','c','d']
y=[1,2,3,4]
pl.plot(x,y)

但是,使用matplotlib绘图程序包时,您会收到一条警告,提示数据不是浮点数(ValueError:float()的无效文字:a).

However, with matplotlib plot packages you get a warning that the data is not float (ValueError: invalid literal for float(): a).

在他们的操作方法" 中,他们建议首先将数值数据放在x轴上,然后对其进行格式化. 有没有办法直接做到这一点(如上所述)?

In their 'How-to', they suggest to put first the numerical data on the x axis and then format it. Is there a way to do it directly (as above)?

推荐答案

使用 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆