根据事物(如产品,服务等)的两个重要属性(指标)作为分析依据,进行关联分析,找出解决问题的一种分析方法。 如何使用Python进行矩阵分析呢 各个省份的GDP-人口矩阵分析,代码实现如下:
import pandas
import matplotlib
import matplotlib.pyplot as plt
mainColor = (42/256, 87/256, 141/256, 1);
#设置字体
font = {
'family': 'SimHei',
'size': 20
}
matplotlib.rc('font', **font);
data = pandas.read_csv(
'D:\\PDA\\5.8\\data.csv'
)
fig = plt.figure(
figsize=(30, 20),
dpi=80
)
sp = fig.add_subplot(111)
sp.set_xlim([
0,
data.GDP.max()*1.1
])
sp.set_ylim([
0,
data.population.max()*1.1
])
#关闭坐标轴、坐标轴的刻度值
#sp.axis('off')
sp.get_xaxis().set_ticks([])
sp.get_yaxis().set_ticks([])
#画点
sp.scatter(
data.GDP, data.population,
alpha=0.5, s=200, marker="o",
edgecolors=mainColor, linewidths=5
)
#画均值线
sp.axvline(
x=data.GDP.mean(),
linewidth=1, color=mainColor
)
sp.axhline(
y=data.population.mean(),
linewidth=1, color=mainColor
)
sp.axvline(
x=0,
linewidth=3, color=mainColor
)
sp.axhline(
y=0,
linewidth=3, color=mainColor
)
sp.set_xlabel('GDP')
sp.set_ylabel('人口')
#画标签
data.apply(
lambda row: plt.text(
row.GDP,
row.population,
row.province,
fontsize=15
),
axis=1
)
plt.show()
局部图
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有