python excel作图
时间: 2023-09-26 17:08:16 浏览: 102
你可以使用xlwings库来在Python中进行Excel作图。首先,你需要导入xlwings库和其他必要的库,例如os、pandas和numpy。然后,你可以使用xlwings的功能来读取Excel数据并生成图表。具体的步骤如下:
1. 导入必要的库:
import os
import pandas as pd
import numpy as np
import xlwings as xw
2. 读取Excel数据:
data = pd.read_csv('17K 30P.csv', header=100)
3. 将数据保存为Excel文件:
data.to_excel('aaa.xlsx')
4. 打开Excel文件:
app = xw.App(visible=False)
workbook = app.books.open('aaa.xlsx')
worksheet = workbook.sheets['Sheet1']
5. 创建图表:
chart = worksheet.charts.add(left=200, top=0, width=355, height=211)
6. 设置图表的数据源:
chart.set_source_data(worksheet['A1'].expand())
7. 设置图表类型:
chart.chart_type = 'xy_scatter_lines_no_markers'
8. 保存并关闭工作簿:
workbook.save('柱形图.xlsx')
workbook.close()
9. 退出Excel应用程序:
app.quit()
10. 完成操作:
print("completed")
以上是使用xlwings库在Python中进行Excel作图的步骤。你可以根据自己的需求修改代码,例如更改数据源、图表类型等。希望对你有帮助!<span class="em">1</span><span class="em">2</span>
#### 引用[.reference_title]
- *1* [python excel画图](https://blog.csdn.net/weixin_44712173/article/details/124240316)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [Python读取Excel数据并生成图表过程解析](https://download.csdn.net/download/weixin_38625448/12850644)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文