python实现可视化 基础(全)

建立坐标系

import matplotlib.pyplot as plt
#导入matplotlib库
%matplotlib inline
#让图标直接在juper notebook中展示
plt.rcParams[“font.sans-serif”]=‘SimHei’
#解决中文乱码问题
plt.rcParams[‘axes.unicode_minus’]=False
#解决负号无法正常显示的问题
%config InlineBackend.figure_format=‘svg’
#将图表显示成矢量图格式
fig=plt.figure()
#开始建立画布

plt.figure(figsize=(100,100))
#画布的大小
#用add_subplot函数建立坐标系
#1*1坐标系
ax1=fig.add_subplot(1,1,1)

注意:建立坐标系的方式有两种:
1.先建立画布,再建坐标系:
fig=plt.figure()
ax1=fig.add_subplot(2,2,1)
2.直接建坐标系
plt.subplot2grid((2,2),(0,0))
3.plt.subplot(2,2,4)
plt.subplot(2,2,1) #分别显示第一个坐标轴和第四个坐标轴
或者 plt.subplots(2,2)
#可以一次性返回多个坐标轴,#将图标的整个区域分成2行2列,并将4个坐标轴全部返回

输出如下:
建立2*2坐标系
fig=plt.figure()
ax1=fig.add_subplot(2,2,1)
ax2=fig.add_subplot(2,2,2)
ax3=fig.add_subplot(2,2,3)
ax4=fig.add_subplot(2,2,4)

在这里插入图片描述
plt.subplot2grid((2,2),(0,0)) #将图标的整个区域分成2行2列:
在这里插入图片描述

在这里插入图片描述

输入数据,作图

import numpy as np
x=np.arange(6)
y=np.arange(6)
fig,axes=plt.subplots(2,2)
axes[0,0].plot(x,y) #在【0,0】坐标系中绘制折线图
axes[0,1].bar(x,y) #在[0,1]坐标系中绘制柱状图

在这里插入图片描述
x=np.array([1,2,3,4,5,6,7,8,9])
y=np.array([866,2335,5710,6482,6120,1605,3813,4428,4631])
plt.subplot(2,1,1)
plt.plot(x,y)
plt.xlabel(“月份”)
plt.ylabel(“注册人数”)
plt.tick_params(axis=“both”,which=“both”,direction=“inout”,bottom=“false”) # 在第1个坐标系中绘图:将轴刻度线设置成双向且下轴刻度线不显示
x=np.array([1,2,3,4,5,6,7,8,9])
y=np.array([866,2335,5710,6482,6120,1605,3813,4428,4631])
plt.subplot(2,1,2)
plt.plot(x,y)
plt.xlabel(“月份”)
plt.ylabel(“注册人数”)
plt.tick_params(axis=“both”,which=“both”,direction=“inout”,labelbottom=“false”) # 在第2个坐标系中绘图:将轴刻度线设置成双向且下轴刻度标签不显示

在这里插入图片描述

其他参数:
plt.axis(“off”)# 不显示坐标轴
plt.grid(b=“true”) #b="True"默认是将xy轴的网格线打开
plt.grid(b=“true”,axis=“x”) #加上axis条件是把x轴的网格线打开
plt.grid(b=“True”,linestyle=“dashed”,linewidth=1) #虚线 线宽为1

在这里插入图片描述

在这里插入图片描述

#在图表下面添加数据表,
rows=[“任务量”,“完成量”] #行标签
columns=[“东区”,“西区”,“南区”,“北区”] #列标签

cellText=[[8566,5335,7310,6482],[4283,2668,3655,3241]] #表的数值
plt.table(cellText=cellText, #表内数值
cellLoc=“center”, #数据表中数值的位置
rowLabels=rows, #行标签
rowColours=[“red”,“yellow”], #行标签的颜色
rowLoc=“center”, #行标签的位置
colLabels=columns, #列标签
colColours=[“red”,“yellow”,“red”,“yellow”], #列标签的颜色
colLoc=“left”,#列标签的位置
loc=“bottom”) #数据表在坐标系中的位置 上下左右

该图主要为了展示图下面的列表

  • 17
    点赞
  • 89
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值