Python数据处理之数据可视化(二)
本篇使用数据:口袋妖怪数据集:提取码s30w
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
# 导入数据
data=pd.read_csv('..\data\pokemon\Pokemon.csv')
x=data['#'].tolist()
speed=data['Speed'].tolist()
defense=data['Defense'].tolist()
# print(x)
# print(speed)
# print(defense)
plt.figure(figsize=(8,6))
gs=gridspec.GridSpec(5,2)
ax1=plt.subplot(gs[:2,:2])
ax2=plt.subplot(gs[-2:,0])
ax3=plt.subplot(gs[-2:,1])
# print(data.Speed)
# 线图
# 绘制两条曲线,Speed和Defense;
ax1.plot(x,speed,color='blue',label='Speed',linewidth=1,alpha=.5,linestyle=':')
ax1.plot(x,defense,color='red',label='Defense',linewidth=1,alpha=.5,linestyle='-')
ax1.legend(loc='upper right')#在图像中显示标签
ax1.set_xlabel('x axis')#定义x轴名称
ax1.set_ylabel('y axis')#定义y轴名称
ax1.set_title('line plot')#定义图像名称
#散点图x=attack,y=defense
ax2.scatter(data.Attack,data.Defense,alpha=.5,color='green')
ax2.set_xlabel('Attack')
ax2.set_ylabel('Defense')
ax2.set_title('Attack Defense Scatter Plot')
# 直方图(速度)
ax3.hist(speed,bins=10)
ax3.set_xlabel('speed')
ax3.set_ylabel('frequence')
plt.show()
运行结果
自学自用,希望可以和大家积极沟通交流,小伙伴们加油鸭,如有错误还请指正,不喜勿喷