2016-08-23 119 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()