11 - 15 绝地求生值数分

1、基本步骤

#1. 导入库 pyhdfs/pandas
#2.把处理好的数据读取进来
#3.导入可视化库 matplotlib /seaborn
#4.作图

#seaborn什么库? Seaborn是一个使用Python制作统计图形的库,
基于matplotlib之上的封装,更加绘图命令更简洁,
#通常会配合pandas读写数据和matplotlib扩展绘图一起使用。
# HdfsClient 是用来连接hadoop集群,从而获取数据

#pyhdfs 什么库? hadoop 集群连接库
from pyhdfs import HdfsClient
import pandas as pd
import matplotlib.pyplot as plt   # 该库主要作用是用来保存图片用的
import seaborn as sns

#1. 从数据库或 hadoop集群上读取数据
# client=HdfsClient(host='****')
# drive=pd.read_excel(client.open("C:\database\study.xlsx"),index_col=0) 

#2. 从本地读取数据
drive=pd.read_excel("C:\database大吉\study.xlsx",index_col=0)
 # 目录中出现中文也是可以的

# pandas 读取数据时会自动增加一个索引列, index_col=0 去除索引列
print(drive)
          won
drive        
0      0.0876
1      1.5653

错误集合

#1.  invalid character in identifier--标识符中有无效字符 
  invalid 无效的 ,character  性格,字符  identifier 辨别,区别,标识符
%matplotlib inline
plt.rcParams['font.sans-serif']=['SimHei'] #指默认字体
plt.rcParams['axes.unicode_minus']=False   #解决保存图像是负号‘-’显示为方块的问题

#Matplotlib展示的图形允许用户有交互动作,例如缩放、平移、保存等,此时,我们需要调用plt.show()来将程序挂起,
#直到手动将图像窗口关闭,否则程序与不会向下执行。
#但将Matplotlib嵌入Jupyter之后,这种Matplotlib生成的图像就处于一种非交互的模式,
#而%matplotlib inline命令就是激活Matplotlib,为Ipython和Jupyter提供“内嵌后端”支持,
#也就是作为一个静态图像嵌入Jupyer中,因此Matplotlib就不需要使用plt.show()来主动调用图像展示窗口。

#数据
#fig  ---figsize 画布大小

drive.plot.bar(fig=(6,3))

在这里插入图片描述

#解决上述备注数字 竖立问题 --rot=0  
drive.plot.bar(fig=(6,3),rot=0) 

在这里插入图片描述

drive.plot.bar(fig=(6,3),rot=0) 
plt.xlabel("是否搭乘过车辆",fontsize=16)
plt.ylabel("吃鸡的概率",fontsize=19)
plt.title("搭乘车与是否成功吃鸡的关系",fontsize=20)

plt.xticks([1,0],['是','否']) #表示x轴数据名字的改变

在这里插入图片描述

横向图的绘制

drive.plot.barh(fig=(6,3),rot=0) 
plt.ylabel("是否搭乘过车辆",fontsize=16)
plt.xlabel("吃鸡的概率",fontsize=19)
plt.title("搭乘车与是否成功吃鸡的关系",fontsize=20)

plt.yticks([1,0],['是','否']) #表示x轴数据名字的改变
plt.savefig('C:\database大吉\我们的第一张图片')   #将图片保存到指定目录下

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_46400833/article/details/109713173