Skip to main content
 首页 » 编程设计

python之如何在 matplotlib 图中设置多年的 X 轴限制

2024年10月01日8qlqwjy

我有一个情节如下:

%matplotlib inline 
import matplotlib.pyplot as plt 
 
df[['Year','Unemployment with primary education (% of total  
unemployment)','Unemployment with secondary education (% of total  
unemployment)','Unemployment with tertiary education (% of total  
unemployment)']].set_index('Year').plot() 
 
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5)) 

我只想将 x 轴限制为 2005 年。我该怎么做?

请您参考如下方法:

我没有你的数据,但如果 'year' 是一个简单的数字,你可以通过调用

来设置限制
plt.xlim(None, 2005)