2016-05-16 6 views

答えて

2

次の2つのプロットのようなものを構築し、この二軸であることをそれらのいずれかのx軸を使用する必要があるとしています。あなたのプロットには、ティックとその位置のラベルを設定するような他の機能があります。あなたはあなたの問題に適応することができるはずですので、次の例では、これらの各要素にビットを果たしている:

import numpy as np 
import matplotlib.pyplot as plt 

fig = plt.figure() 
ax1 = fig.add_subplot(111) 
ax2 = ax1.twiny() 

# Add some extra space for the second axis at the bottom 
fig.subplots_adjust(bottom=0.2) 
ax1.set_xticks([1,2,4,5,7,8]) 
ax1.set_xlim(0,9) 
ax1.set_xticklabels(('2015','2016','2015','2016','2015','2016')) 
ax2.spines["bottom"].set_position(("axes", -0.15)) 
ax2.xaxis.set_ticks_position("bottom") 
ax2.spines["bottom"].set_visible(True) 
ax2.set_xticks([1.5,4.5,7.5]) 
ax2.set_xticklabels(('1','2','3')) 
ax2.set_xlim(0,9) 

b1 = np.random.randint(0,100,6) 
b2 = np.random.randint(0,100,6) 
b3 = np.random.randint(0,100,6) 
plt.bar(np.array([1,2,4,5,7,8])-0.4,b1,color='blue') 
plt.bar(np.array([1,2,4,5,7,8])-0.4,b2,color='orange',bottom=b1) 
plt.bar(np.array([1,2,4,5,7,8])-0.4,b3,color='yellow',bottom=b1+b2) 

plt.show() 

、結果はこれです:

Two axis in a stacked bar plot in matplotlib

関連する問題