说明:适合初学者查看练习。
基本语法介绍:
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
font_set = FontProperties(fname = r"c:\windows\fonts\msyh.ttc",size=14) # 设置字体
plt.title("数据可视化",fontproperties=font_set) # 图标标题
plt.xlabel("X轴方向",fontproperties=font_set) # X轴标题
plt.ylabel("Y轴方向",fontproperties=font_set) # Y轴标题
plt.rcParams['figure.figsize'] = (16.0, 8.0) # 设置figure_size尺寸
plt.plot([1,2,3,4],[1,4,2,3])
plt.show() # 数据展示
数据展示:
数据下载:
https://download.csdn.net/download/weixin_44940488/12466159
全部代码展示:
from pyecharts.charts import Bar # 生成图标,数据可视化
import xlrd # 读取分离 读:xlrd(read) 写:xlwt(write)
data = xlrd.open_workbook('销售数据.xlsx')
table = data.sheets()[0] # 通过下标索引获取
names = []
sales = []
for i in range(1,table.nrows):
name = table.row_values(i)[0]
names.append(name)
sale = table.row_values(i)[2]
sales.append(sale)
bar = Bar() # 生成簇状统计图
bar.add_xaxis(names)
bar.add_yaxis('业务详情', sales)
bar.render('销售数据可视化.html')
结果展示:
全部代码:
from pyecharts.charts import Bar
from pyecharts import options as opts
# 内置主题类型可查看 pyecharts.globals.ThemeType
from pyecharts.globals import ThemeType
bar = (
Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])
.add_yaxis("商家A", [5, 20, 36, 10, 75, 90])
.add_yaxis("商家B", [15, 6, 45, 20, 35, 66])
.set_global_opts(title_opts=opts.TitleOpts(title="商品数据可视化", subtitle="副标题"))
)
bar.render('商品数据可视化.html')
结果展示: