質問

Ok, I searched a lot about it but still I didn't get it quite well... Suppose I have:

listHours = ['00:00:000-10:00:000', '10:00:000-20:00:000', '20:00:000-30:00:000',    '30:00:000-40:00:000', '40:00:000-50:00:000', '50:00:000-00:00:000']
listNumbers = ['0.01', '0.02', '0.03', '0.05', '0.05', '0.03'] 

and I want:

plt.plot(listHours, listNumbers)
plt.show()

Matplotlib is not accepting this listHours ("ValueError: invalid literal for float(): 00:00:000-10:00:000") when I use ticks I get this error: "TypeError: float() argument must be a string or a number" I don't know if it's because I'm using this ticks thing wrong or whatever... any idea? I'm kinda frustrated here.

Thanks already.

役に立ちましたか?

解決

You can use the xticks command to do so. See the following snippet -

>>> listHours = ['00:00:000-10:00:000', '10:00:000-20:00:000', '20:00:000-30:00:000','30:00:000-40:00:000', '40:00:000-50:00:000', '50:00:000-00:00:000']
>>> listNumbers = ['0.01', '0.02', '0.03', '0.05', '0.05', '0.03']
>>> listNumbers = [float(elem) for elem in listNumbers]  # Convert to a list of floats.
>>> plt.plot(listNumbers)
>>> plt.xticks(range(len(listHours)), listHours, size='small')
>>> plt.show()

It gives you a figure like this

Plot figure

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top