2014-10-31 35 views
1

在x軸上,我想在每個數字下面顯示帶有旋轉名稱的數字(不帶旋轉)。我有以下內容,但想單獨旋轉名稱'one','two'和'three'。xticks的旋轉部分

plt.xticks([1,2,3], ['1\n one', '2\n two', '3\n three'], rotation=45] 
+0

什麼'plt'?你在使用某種圖書館嗎? – Kevin 2014-10-31 12:40:10

+1

@Kevin:一個非常有效的問題,但我認爲這是保存假設OP使用* matplotlib * – hitzg 2014-10-31 13:12:52

+0

道歉,我應該包括行:'import matplotlib.pyplot as plt' – user1048442 2014-11-07 12:57:13

回答

3

您可以將主要和次要蜱放在相同的位置。下面是一個最小的例子:(從this answer一些啓發)

import pylab as pl 

pl.clf() 
ax = pl.gca() 
ax.set_xticks([1, 2, 3]) 
ax.set_xticks([1, 2, 3], minor=True) 
ax.set_xticklabels(['one', 'two', 'three'], minor=True) 
pl.setp(ax.xaxis.get_minorticklabels(), rotation=-45) 

for t in ax.get_xticklabels(minor=True): 
    t.set_y(-0.03) 

enter image description here