pyecharts官方示例如下: https://gallery.pyecharts.org/#/Bar/bar_base
代码:
from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.options.global_options import AxisOpts
from pyecharts.render import make_snapshot
from snapshot_selenium import snapshot
import pandas as pd
import numpy as np
import xlsxwriter as xlwt
import openpyxl
def make_bar(x,y):
bar = Bar()
bar.add_xaxis(xaxis_data=x)
bar.add_yaxis(series_name='1', y_axis=y)
bar.set_global_opts(title_opts=opts.TitleOpts(title='柱状图示例'))
make_snapshot(snapshot, bar.render('datatest.html'), "datatest.png")
def main():
path = r'C:\Users\hp\Desktop\dataset.xlsx'
temp_data = pd.read_excel(path, sheet_name='六、主观自我评价', engine='openpyxl')
y_list=[]
Closewindows= temp_data['第2组测评分']
len_data=10
for i, data in enumerate(Closewindows):
if i<10:
y_list.append(data)
make_bar(len_data,y_list)
if __name__ == '__main__':
main()
中途保存图片的时候报错了: selenium.common.exceptions.WebDriverException: Message: ‘chromedriver’ executable needs to be in PATH. 原因是用了谷歌浏览器去渲染图片,但是谷歌浏览器没有驱动。 解决参考: https://blog.csdn.net/u011318077/article/details/90113206
|