2016-07-18 3 views
2

나는 7 개의 파이 차트를 가지고 있습니다 (아래에 4 개가 나와 있습니다). 나는 첫 번째 줄에 4 개의 원형 차트와 두 번째 줄에 3 개의 원형 차트가있는 대시 보드를 만들려고합니다. 아래 코드로 어디서 잘못 될지 잘 모르겠습니다. 이것을 달성하기위한 다른 대안이 있습니까? 어떤 도움을 주시면 감사하겠습니다.matplotlib 서브 플로트를 사용한 파이 차트 배열

from matplotlib import pyplot as PLT 
fig = PLT.figure() 
ax1 = fig.add_subplot(221) 
line1 = plt.pie(df_14,colors=("g","r")) 
plt.title('EventLogs') 
ax1 = fig.add_subplot(223) 
line2 = plt.pie(df_24,colors=("g","r")) 
plt.title('InstalledApp') 
ax1 = fig.add_subplot(222) 
line3 = plt.pie(df_34,colors=("g","r")) 
plt.title('Drive') 
ax1 = fig.add_subplot(224) 
line4 = plt.pie(df_44,colors=("g","r")) 
plt.title('SQL Job') 
ax1 = fig.add_subplot(321) 
line5 = plt.pie(df_54,colors=("g","r")) 
plt.title('Administrators') 
ax2 = fig.add_subplot(212) 
PLT.show() 

답변

1

내가 항상 사용하고 나를 위해 AT-이상,보다 직관적 인 더 나은 방법은 subplot2grid ....

fig = plt.figure(figsize=(18,10), dpi=1600) 
#this line will produce a figure which has 2 row 
#and 4 columns 
#(0, 0) specifies the left upper coordinate of your plot 
ax1 = plt.subplot2grid((2,4),(0,0)) 
plt.pie(df_14,colors=("g","r")) 
plt.title('EventLogs') 
#next one 
ax1 = plt.subplot2grid((2, 4), (0, 1)) 
plt.pie(df_24,colors=("g","r")) 
plt.title('InstalledApp') 

을 사용하는 것입니다 그리고 당신은 같이 갈 때, 그리고 수 당신은 행을 전환하려면 (1, 0) ... 두 번째 행 우선 열로 좌표를 써야합니다.

2 행과 2 COLS와 예 -

fig = plt.figure(figsize=(18,10), dpi=1600) 
#2 rows 2 cols 
#first row, first col 
ax1 = plt.subplot2grid((2,2),(0,0)) 
plt.pie(df.a,colors=("g","r")) 
plt.title('EventLogs') 
#first row sec col 
ax1 = plt.subplot2grid((2,2), (0, 1)) 
plt.pie(df.a,colors=("g","r")) 
plt.title('EventLog_2') 
#Second row first column 
ax1 = plt.subplot2grid((2,2), (1, 0)) 
plt.pie(df.a,colors=("g","r")) 
plt.title('InstalledApp') 
#second row second column 
ax1 = plt.subplot2grid((2,2), (1, 1)) 
plt.pie(df.a,colors=("g","r")) 
plt.title('InstalledApp_2') 

enter image description here

희망이 도움이!

+0

감사합니다. 완벽하게 작동합니다. 7 개 플롯 모두에 공통된 전설을 설정하는 방법이 있습니까? 예를 들어 빨간색은 '건강하지 않음'으로, 녹색은 '건강'으로 표시됩니까? – user3447653

+0

당신은'figlegend'를 찾고 있습니다. 그러나 각각의 플롯이 그들 자신의 축을 가지고 있기 때문에'legend'와 직접적으로 그것을 할 수 없습니다. 아니면 단지 한 음모에 대한 전설을 배치하지 않는 이유는 무엇입니까? – hashcode55

+0

나는 이것을 시도했지만 기대했던대로 작동하지 않는다 : lgd = plt.legend ((line1), ('Helathy', 'Not Healthy'), loc = 'right right') – user3447653