2017-03-17 89 views
1

我已經使用下面的一段代碼作出了附圖。我試圖命名代碼中的不同部分,但名稱(B1,S和B2,分別爲上半部分,中間部分和下半部分)未包含在該圖中。包含劇情中的名字python

fig, ax = pyplot.subplots(1, 1, figsize=(9, 4.5)) 
xmax = vc.shape[0] 
for isample, sample in enumerate(sampleinfo): 
    ax.plot(vc[:, isample], color=sample[3], label="%s\n$n=%d$" % (sample[2], ws[isample])) 
ax.set_xlim([0, 2*xmax/3]) 
ax.set_xticklabels(["B1", "S" "B2"], ha="center", weight="bold") 
ax.get_xticklabels()[0].set_horizontalalignment("center") 
ax.get_xticklabels()[-1].set_horizontalalignment("center") 
ax.set_ylabel("Aount)") 

這裏我得到的數字使用的代碼:

enter image description here

你知道如何包含在情節的名字?

我希望有一個情節是這樣的:

enter image description here

+0

你怎麼想的圖表看標記它們隨後? – Crispin

+0

這個問題是eddited。 – user7249622

回答

0

使用域的大小來確定季度,半年和三季度在x軸標記。通過這些地點ax.set_xticks和使用set_xticklabels

import matplotlib.pyplot as plt 

fig, ax = plt.subplots(1, 1, figsize=(9, 4.5)) 
x = [1,2,4] 
y = [4,5,6] 
ax.plot(x,y) 

xmin, xmax = ax.get_xlim() 
domain = xmax - xmin 

tick_locations = (xmin + domain/4,xmin+domain/2, xmax-domain/4) 
ax.set_xticks(tick_locations) 
ax.set_xticklabels(["B1", "S", "B2"], ha='center') 

ax.set_ylabel("Amount)") 

plt.show() 

enter image description here