pyecharts画图
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from pyecharts.charts import Bar
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
#导入Excel数据
data=pd.read_excel("***.xlsx")
data
#柱状图的实现
from pyecharts import options as opts
bar=Bar()
xindex=['属性1','属性2','属性3']
bar.add_xaxis(xaxis_data=xindex)
xaxis_opts=opts.AxisOpts(axislabel_opts={"interval":"0"})
xaxis_opts=opts.AxisOpts(axislabel_opts={"rotate":45})
bar.add_yaxis('属性列','展示结果列'.tolist(),color='bisque')
bar.add_yaxis('属性列','展示结果列'.tolist(),color='plum')
bar.set_global_opts(title_opts=opts.TitleOpts(title='题目',subtitle='小题目'))
bar.render_notebook()
举个例子吧!
grade=pd.read_excel("期中考试成绩.xlsx")
grade
from pyecharts import options as opts
bar=Bar()
xindex=['语文','数学','英语','物理','化学','生物']
bar.add_xaxis(xaxis_data=xindex)
bar.add_yaxis(grade.columns[2],grade['平均成绩(女)'].tolist(),color='bisque')
bar.add_yaxis(grade.columns[1],grade['平均成绩(男)'].tolist(),color='plum')
bar.set_global_opts(title_opts=opts.TitleOpts(title='期中考试男女平均成绩比较',subtitle='2022.3.26'))
bar.render_notebook()
#堆叠图
import pyecharts.options as opts
from pyecharts.charts import Bar
subject = ['语文','数学','英语','物理','化学','生物']
bar = (
Bar()
.add_xaxis(subject)
.add_yaxis('平均成绩(女)', grade['平均成绩(女)'].tolist(), stack='stack1',color='darkseagreen')
.add_yaxis('平均成绩(男)', grade['平均成绩(男)'].tolist(), stack='stack1',color='tan')
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(title_opts=opts.TitleOpts(title='期中考试男女平均成绩比较'),
xaxis_opts=opts.AxisOpts(name='学科'),
yaxis_opts=opts.AxisOpts(name='平均成绩'))
)
bar.render('期中考试男女平均成绩比较堆叠图.html')