2010-08-10 61 views
0

我想要保持酒吧的寬度相同無論酒吧的數量比較高或低。 我正在使用Matplotlib堆積條形圖。 酒吧的寬度是相對於酒吧的數量。 這是我的示例代碼。無論圖中我們比較的鋼筋數量如何保持鋼筋寬度相同?

我怎樣才能使寬度相同的,無論我從1比作10

import numpy as np 
import matplotlib.pyplot as plt 




N =1 
ind = np.arange(N) # the x locations for the groups 
width = 0.35  # the width of the bars: can also be len(x) sequence 




design = [] 
arch = [] 
code = [] 

fig = plt.figure() 



b = [70] 
a= np.array([73]) 
c = [66] 




p1 = plt.bar(ind, a,width, color='#263F6A') 
p2 = plt.bar(ind, b, width, color='#3F9AC9', bottom=a) 
p3 = plt.bar(ind, c, width, color='#76787A', bottom=a+b) 


plt.ylabel('Scores') 
plt.title('CQI Index') 


plt.xticks(ind+width/2., ('P1'))#dynamic - fed 

plt.yticks(np.arange(0,300,15)) 


plt.legend((p1[0], p2[0], p3[0]), ('A','B','C')) 
plt.grid(True) 

plt.show() 

的條數謝謝

回答

2

條的寬度並沒有改變,規模你的形象改變了。如果你想規模保持不變,你必須手動指定要顯示什麼範圍,你的情節是否爲10×10,100×100,或10億×10

編輯:

如果我理解正確,你想要的是這樣的:

圖1 - 2條:

10 
+---------------------------+ 
|       | 
|       | 
|       | 
|       | 
|       | 
|  4_     | 
|  | |     | 
| 2_ | |     | 
| | | | |     | 
| | | | |     | 
+---------------------------+ 10 

圖2 - 增加2個酒吧

10 
+---------------------------+ 
|       | 
|       | 
|     7_  | 
|     | |  | 
|     | |  | 
|  4_  | |  | 
|  | | 3_ | |  | 
| 2_ | | | | | |  | 
| | | | | | | | |  | 
| | | | | | | | |  | 
+---------------------------+ 10 

凡條的外觀寬度並沒有改變,從圖1至圖2.如果這是你想做的事,那麼你就需要設置你的陰謀的規模是什麼

你可以做與

import matplotlib 
matplotlib.use('GTKAgg') 

import matplotlib.pyplot as plt 
import gobject 

fig = plt.figure() 
ax = fig.add_subplot(111) 

def draw1(): 
    plt.bar(0,2) 
    plt.bar(2,4) 
    ax.set_xlim((0,10)) 
    ax.set_ylim((0,10)) 
    fig.canvas.draw() 
    return False 

def draw2(): 
    plt.bar(4,3) 
    plt.bar(6,7) 

    ax.set_xlim((0,10)) 
    ax.set_ylim((0,10)) 
    fig.canvas.draw() 
    return False 

draw1() 
gobject.timeout_add(1000, draw2) 
plt.show() 
+0

我同意,寬度總是在開始時指定的。 我實際上的意思是我想讓刻度自動改變,以防止酒吧擠壓以適應情節區域。 我的意思是繪圖區應該是動態的。因此,不要將繪圖區域劃分爲多個條形圖,我們可以將一個圖形區域添加到另一個圖形區域直到10個圖形區域。 – Atlas 2010-08-10 11:40:21

+0

我添加了一個編輯...是你在找什麼? – 2010-08-10 14:42:31

+0

對不起,如果我沒有明確表達自己。添加圖形不是我正在尋找的功能。這是一個比喻。 我不想添加酒吧。我只是想解釋一下,無論圖中的條數是多少,寬度都應該看起來相同。他們不應該劃分數字,否則我們需要的條數越多,我們得到的圖形越小。 他們應該強迫這個數字擴大一點,讓他們看起來是一樣的。否則,如果我們繪製一個小節,它不應該像上面的示例那樣佔用整個空間。 謝謝 – Atlas 2010-08-10 15:09:01

相關問題