2014-09-23 113 views
2

如何使用pylab繪製stringfloat類型圖?我怎麼能在python中繪製字符串vs浮點數?

x = ['PARIS','LONDON'] 

y = [2.39, 3.41] 

我怎麼能繪製xy

+1

您需要分配到y'的'值水平的關係,然後指定你的字符串作爲'ticks'。 – 2014-09-23 15:07:19

+0

@MylesBaker謝謝! – wthimdh 2014-09-23 15:51:27

回答

7

非常感謝邁爾斯·貝克,這裏是解決方案:

import pylab as pl 
x = [0,1] 
xTicks = ['LONDON','PARIS'] 
y = [2.39, 3.41] 
pl.xticks(x, xTicks) 
pl.xticks(range(2), xTicks, rotation=45) #writes strings with 45 degree angle 
pl.plot(x,y,'*') 
pl.show() 
+0

有沒有一種等價的方法來做到這一點單軸?我試過'ax.set_xticks()'和'ax.set_xticklabels()',它們似乎被忽略了...... – naught101 2015-08-19 05:33:24

相關問題