點擊藍字【秋葉 Excel】
發送【7】
免費領 1000+篇 Excel 精選教程!
本文作者:拉登Dony
本文來源:拉小登
本文編輯:竺蘭
大家好,這里是秋葉編輯部~
你知道嗎?WPS 里的 Python 能直接生成圖表,如下圖:
而且這些圖表,還有動態交互效果,實在是太強了!
方法特別簡單,只需要根據下面的步驟,套用模板就行。
即使你是零基礎,不會寫代碼,也能參考今天的教程輕松上手制作這樣的圖表。
其實,掌握 AI 并不難,難的是踏出嘗試新工具的第一步~
無論是對 AI 感興趣想試試看,還是有需求(升職加薪或做副業),你都可以加入《DeepSeek 3 天辦公實戰營》學習一下新技能!
原價 99 元
3 天課程手把手帶你學習:
AI 數據分析、AI 寫作、AI PPT ……
還能免費獲得 DeepSeek 學習資料包
名額有限,立即掃碼報名吧!
掃碼報名后自動彈出班主任微信
一定要添加,才能上課+免費領取資料
基礎用法
這些圖表都是基于百度開源的PyEcharts框架生成的,找到模板直接套用即可。
?進入官網
首先進入 PyEcharts 的官網。網址:
https://gallery.pyecharts.org/#/README
左邊是所有的圖表模板清單,數量巨多,點擊就能查看圖表預覽效果,以及對應的代碼。
?復制圖表代碼
我們以最簡單的柱形圖為例,點擊【Sankey - Sankey_base】這個模板,點擊右上角的【復制代碼】。
?粘貼圖表代碼
① 新建多維表格
接下來,進入金山文檔,新建一個多維表格。
② 新建腳本
在效率選項卡中點擊【PY腳本】【新建腳本】。
③ 粘貼代碼
把復制的代碼,粘貼到編輯區域。
from pyecharts import options as opts
from pyecharts.charts import Sankey
nodes = [
{"name": "category1"},
{"name": "category2"},
{"name": "category3"},
{"name": "category4"},
{"name": "category5"},
{"name": "category6"},
]
links = [
{"source": "category1", "target": "category2", "value": 10},
{"source": "category2", "target": "category3", "value": 15},
{"source": "category3", "target": "category4", "value": 20},
{"source": "category5", "target": "category6", "value": 25},
]
c = (
Sankey()
.add(
"sankey",
nodes,
links,
linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source"),
label_opts=opts.LabelOpts(position="right"),
)
.set_global_opts(title_opts=opts.TitleOpts(title="Sankey-基本示例"))
.render("sankey_base.html")
)
④ 調整代碼
在代碼中找到【c=】,刪除掉。
修改后代碼如下:
from pyecharts import options as opts
from pyecharts.charts import Sankey
nodes = [
{"name": "category1"},
{"name": "category2"},
{"name": "category3"},
{"name": "category4"},
{"name": "category5"},
{"name": "category6"},
]
links = [
{"source": "category1", "target": "category2", "value": 10},
{"source": "category2", "target": "category3", "value": 15},
{"source": "category3", "target": "category4", "value": 20},
{"source": "category5", "target": "category6", "value": 25},
]
(
Sankey()
.add(
"sankey",
nodes,
links,
linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source"),
label_opts=opts.LabelOpts(position="right"),
)
.set_global_opts(title_opts=opts.TitleOpts(title="Sankey-基本示例"))
.render("sankey_base.html")
)
然后點擊【運行】執行代碼。
稍后圖表就會在下面出現預覽效果,點擊插入到表格就搞定了,就是這么簡單。
重復上面的步驟,可以制作更多精美圖表。
進階教程
你可能在網上看到過 PyEechart+WPS 表格的圖表方法,大部分博主講到這兒就結束了。
然后你就跟風去嘗試了,做出一堆花里胡哨的圖表,但是回到工作中,第 1 步就做不下去了。
原因是不知道怎么改數據!!!!
我從來都是講實用的,落地的方法,馬上教你,把 PyEcharts 改成自己的數據!
?提取圖表數據
把復制好的代碼,發給豆包,讓豆包幫我們把代碼中的數據提取出來,并用表格的形式顯示。
請提取代碼中的數據,并用表格的形式輸出
from pyecharts import options as opts
from pyecharts.charts import Sankey
nodes = [
{"name": "category1"},
{"name": "category2"},
{"name": "category3"},
{"name": "category4"},
{"name": "category5"},
{"name": "category6"},
]
links = [
{"source": "category1", "target": "category2", "value": 10},
{"source": "category2", "target": "category3", "value": 15},
{"source": "category3", "target": "category4", "value": 20},
{"source": "category5", "target": "category6", "value": 25},
]
(
Sankey()
.add(
"sankey",
nodes,
links,
linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source"),
label_opts=opts.LabelOpts(position="right"),
)
.set_global_opts(title_opts=opts.TitleOpts(title="Sankey-基本示例"))
.render("sankey_base.html")
)
AI 可以幫我們讀懂代碼內容,并成功提取數據,效果如下:
?修改圖表數據
有了表格之后,可以輕松的把數據改成我們自己的。
然后,把新的數據發給豆包,讓 AI 把數據寫入到原來的代碼中去。
下面是我修改后的數據,請更新到代碼中去
源節點 目標節點 值
中國 華東 10
華東 山東 15
山東 濟南 20
中國 華北 25
from pyecharts import options as opts
from pyecharts.charts import Sankey
nodes = [
{"name": "中國"},
{"name": "華東"},
{"name": "山東"},
{"name": "濟南"},
{"name": "華北"}
]
links = [
{"source": "中國", "target": "華東", "value": 10},
{"source": "華東", "target": "山東", "value": 15},
{"source": "山東", "target": "濟南", "value": 20},
{"source": "中國", "target": "華北", "value": 25}
]
(
Sankey()
.add(
"sankey",
nodes,
links,
linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source"),
label_opts=opts.LabelOpts(position="right"),
)
.set_global_opts(title_opts=opts.TitleOpts(title="Sankey-基本示例"))
.render("sankey_base.html")
)
接下來,按照前面的步驟,把修改后的代碼,粘貼到金山文檔中,運行就可以得到更新后的圖表。
借助 AI 的力量,確確實實可以提高我們的辦公效率,如果你也想掌握 AI,讓它幫自己打工,
那么,你該加入《DeepSeek 3 天辦公實戰營》了!
在課程中,不僅有金牌講師 @AI陳手把手教學 AI 數據分析、AI 寫文案、AI 設計、AI 做 PPT,助你提高效率、減輕工作壓力~
現在報名,還能免費領取《DeepSeek 學習資料包》!
課程原價 99 元
?秋葉實戰派老師教學
?專業助教隨時答疑
?掌握多種 AI 神器
名額有限,立即掃碼報名
讓 AI 幫你打工!
掃碼報名后自動彈出班主任微信
一定要添加,才能上課+免費領取資料
關注我,每天學習新的知識,一起成長!
想學什么內容,可以在評論區給我悄悄留言哦~
特別聲明:以上內容(如有圖片或視頻亦包括在內)為自媒體平臺“網易號”用戶上傳并發布,本平臺僅提供信息存儲服務。
Notice: The content above (including the pictures and videos if any) is uploaded and posted by a user of NetEase Hao, which is a social media platform and only provides information storage services.