2016-08-23 131 views
0

我有以下graphMatplotlib圖展開x軸

import matplotlib.pyplot as plt 
import numpy as np 
fig = plt.figure() 


x_values = [2**6,2**7,2**8,2**9,2**10,2**12] 
y_values_ST = [7.3,15,29,58,117,468]  
y_values_S3 = [2.3,4.6,9.1,19,39,156]  
xticks=['2^6','2^7','2^8','2^9','2^10','2^12'] 

plt.plot(x_values, y_values_ST,'-gv') 
plt.plot(x_values, y_values_S3,'-r+') 
plt.legend(['ST','S^3'], loc='upper left') 
plt.xticks(x_values,xticks) 

fig.suptitle('Encrypted Query Size Overhead') 
plt.xlabel('Query size') 
plt.ylabel('Size in KB') 
plt.grid() 
fig.savefig('token_size_plot.pdf') 
plt.show() 

1)如何刪除2^12之後顯示的最後間隔? 2)如何我可以傳播更多的價值在X軸,使前兩個值不重疊?

回答

1

1)如何刪除2^12之後顯示的最後一個間隙?

明確設置的限制,例如:

plt.xlim(2**5.8, 2**12.2) 

2)我怎樣才能在傳播更多的值x軸,使得前兩個值是不重疊?

你似乎想要一個日誌圖。使用pyplot.semilog(),或者設置日誌的規模在x軸(基數爲2,你的情況似乎比較合適):

plt.xscale('log', basex=2) 

注意,在這種情況下,你甚至不需要設置2^*手動蜱,他們將自動創建這種方式。

enter image description here

0

1.使用autoscale,指定座標軸,或交替您可以使用plt.axis('tight')兩個軸。 2.使用日誌縮放x軸。下面的代碼:

import matplotlib.pyplot as plt 

fig = plt.figure() 

x_values = [2**6,2**7,2**8,2**9,2**10,2**12] 
y_values_ST = [7.3,15,29,58,117,468] 
y_values_S3 = [2.3,4.6,9.1,19,39,156] 
xticks=['2^6','2^7','2^8','2^9','2^10','2^12'] 

ax = plt.gca() 
ax.set_xscale('log') 
plt.plot(x_values, y_values_ST,'-gv') 
plt.plot(x_values, y_values_S3,'-r+') 
plt.legend(['ST','S^3'], loc='upper left') 
plt.xticks(x_values,xticks) 

fig.suptitle('Encrypted Query Size Overhead') 
plt.xlabel('Query size') 
plt.ylabel('Size in KB') 

plt.autoscale(enable=True, axis='x', tight=True)#plt.axis('tight') 
plt.grid() 
fig.savefig('token_size_plot.pdf') 
plt.show()