Matplotlib两轴值重叠

时间:2018-12-28 11:10:38

标签: python matplotlib

刚开始使用Matplotlib时,我已经使用URL导入了csv文件,在该文件中,有大约190多个国家/地区条目,以及该国家/地区所属的特定区域,例如亚洲的印度。我能够绘制所有数据,但是由于这些数据太多,所有X轴和Y轴值彼此重叠并变得混乱。

代码:

country_cols = ['Country', 'Region']
country_data = pd.read_csv("https://raw.githubusercontent.com/cs109/2014_data/master/countries.csv",names=country_cols)

country_list = country_data.Country.tolist()
region_list = country_data.Region.tolist()

plt.plot(region_list,country_list)

输出显示如下

enter image description here

为了学习,我使用的是简单的折线图,我也想知道应该使用哪种图形类型来表示此类数据?这样会很有帮助。

1 个答案:

答案 0 :(得分:0)

我认为您需要fig.autofmt_xdate()

尝试以下代码:

 country_cols = ['Country', 'Region']
 country_data = pd.read_csv("https://raw.githubusercontent.com/cs109/2014_data/master/countries.csv",names=country_cols)

 country_list = country_data.Country.tolist()
 region_list = country_data.Region.tolist()
 fig = plt.figure()
 plt.plot(region_list,country_list)
 fig.autofmt_xdate()
 plt.show()