啥?Python竟然也可以制作萌萌的手绘图表
印象Python
共 4348字,需浏览 9分钟
·
2020-12-14 14:29
![](https://filescdn.proginn.com/c0d565df4ccdedb4d34af44fdeca7323/3d9632289b98dc0724f74feca95dec98.webp)
点击上方蓝字关注我们
![](https://filescdn.proginn.com/f3596917fe0ccad2d4504326f4c57b9c/22b10fa9cfca7affe5e97edc380cdaf1.webp)
![](https://filescdn.proginn.com/5011ef5caf1b56a7246ec26f2b997b36/b55b1a6c022f0b5e16c6a577592b0c5a.webp)
![](https://filescdn.proginn.com/a9a5e1fb8b2552aab95af2443b574763/8ec9e10e7f51c9a0dc154ec7e0bfb100.webp)
$ pip install cutecharts
#import library and data
import cutecharts.charts as ctc
df=pd.DataFrame({
‘x’:[‘Sun.’,’Mon.’,’Tue.’,’Wed.’,’Thu.’,’Fri.’,’Sat.’],
‘y’:[14,15,17,20,22.3,23.7,24.8],
‘z’:[16,16.4,23.6,24.5,19.9,13.6,13.4]})
条形图
chart = ctc.Bar(‘Toronto Temperature’,width=’500px’,height=’400px’)
chart.set_options(
labels=list(df[‘x’]),
x_label='Days',
y_label='Temperature (Celsius)' ,
colors=[‘#1EAFAE’ for i in range(len(df))]
)
chart.add_series('This week',list(df[‘y’]))
chart.render_notebook()
![](https://filescdn.proginn.com/8eddd329f19203778e1bad547884b31c/12a8f5a7fc137269b9929fb0ab2a64ba.webp)
chart = ctc.Bar(‘title’,width=’500px’,height=’400px’)
chart.set_options(
labels=list(df[‘x’]),
x_label=”Days”,
y_label=”Temperature (Celsius)” ,
colors=[‘#FFF1C9’,’#F7B7A3',’#EA5F89',’#9B3192',’#57167E’,’#47B39C’,’#00529B’]
)
chart.add_series(“This week”,list(df[‘y’]))
chart.render_notebook()
![](https://filescdn.proginn.com/13e2582a8597e45526d4cd8488b93987/b3bfa5e5d547a84a50586ce0614ebd40.webp)
线图
chart = ctc.Line(“Toronto Temperature”,width=’500px’,height=’400px’)
chart.set_options(
labels=list(df[‘x’]),
x_label=”Days”,
y_label=”Temperature (Celsius)” )
chart.add_series(“This Week”, list(df[‘y’]))
chart.add_series(“Last Week”, list(df[‘z’]))
chart.render_notebook()
![](https://filescdn.proginn.com/5b17270c9b8038c056504b141e8c3f50/edf3543481aec6d2b085013fd94c93ca.webp)
雷达图
chart = ctc.Radar(‘Toronto Temperature’,width=’700px’,height=’600px’)
chart.set_options(
labels=list(df[‘x’]),
is_show_legend=True, #by default, it is true. You can turn it off.
legend_pos=’upRight’ #location of the legend
)
chart.add_series(‘This week’,list(df[‘y’]))
chart.add_series(“Last week”,list(df[‘z’]))
chart.render_notebook()
![](https://filescdn.proginn.com/0acaa69c3460f7906f25feb27574d041/1e2d00a568003711b38860ad52eb4d2a.webp)
饼图
df=pd.DataFrame({‘x’:[‘Asia’, ‘Africa’, ‘Europe’, ‘North America’, ‘South America’, ‘Australia’],
‘y’:[59.69, 16, 9.94, 7.79, 5.68, 0.54]})
chart = ctc.Pie(‘% of population by continent’,width=’500px’,height=’400px’)
chart.set_options(
labels=list(df[‘x’]),
inner_radius=0
)
chart.add_series(list(df[‘y’]))
chart.render_notebook()
![](https://filescdn.proginn.com/9422ff74b317deea21c6515aa9ba07d5/c3dcaa1bbf4e07bfa96482643855f0b4.webp)
df=pd.DataFrame({‘x’:[‘Asia’, ‘Africa’, ‘Europe’, ‘North America’, ‘South America’, ‘Australia’],
‘y’:[59.69, 16, 9.94, 7.79, 5.68, 0.54]})chart = ctc.Pie(‘% of population by continent’,width=’500px’,height=’400px’)
chart.set_options(
labels=list(df[‘x’]),
inner_radius=0.6
)
chart.add_series(list(df[‘y’]))
chart.render_notebook()
![](https://filescdn.proginn.com/5544c496d2ed29b77a5669a890d02f5d/1e56d6accb2878f3ba0308977248639d.webp)
散点图
Temperature = [14.2,16.4,11.9,15.2,18.5,22.1,19.4,25.1,23.4,18.1,22.6,17.2]
Sales = [215,325,185,332,406,522,412,614,544,421,445,408]
chart = ctc.Scatter(‘Ice Cream Sales vs Temperature’,width=’500px’,height=’600px’)
chart.set_options(
x_label=”Temperature (Celcius)”,
y_label=”Icecream Sales” ,
colors=[‘#1EAFAE’],
is_show_line = False,
dot_size=1)
chart.add_series(“Temperature”, [(z[0], z[1]) for z in zip(Temperature, Sales)])
chart.render_notebook()
![](https://filescdn.proginn.com/79a8f6a296afa4a88b8a4d81a142fd6c/0f1def5f8bcfeb2e6b18b8cb113b4c9c.webp)
组合图
chart1 = ctc.Line(“Toronto Temperature”,width=’500px’,height=’400px’)
chart1.set_options(
labels=list(df[‘x’]),
x_label=”Days”,
y_label=”Temperature (Celsius)” )
chart1.add_series(“This Week”, list(df[‘y’]))
chart1.add_series(“Last Week”, list(df[‘z’]))chart2 = ctc.Bar(‘Toronto Temperature’,width=’500px’,height=’400px’)
chart2.set_options(
labels=list(df[‘x’]),
x_label=”Days”,
y_label=”Temperature (Celsius)” ,
colors=[‘#1EAFAE’ for i in range(len(df))]
)
chart2.add_series(“This week”,list(df[‘y’]))
chart2.add_series(“Last week”,list(df[‘z’]))page = Page()
page.add(chart1, chart2)
page.render_notebook()
![](https://filescdn.proginn.com/e7ce453f55f3e60599beed788864638f/8b45828731b165700714d9c681677d9e.webp)
回复下方 「关键词」,获取优质资源
![](https://filescdn.proginn.com/13c016010a3cb6ebb08d826839e00104/5a1e0886dd88ff24ae54a3bf1e8d52d5.webp)
回复关键词 「linux」,即可获取 185 页 Linux 工具快速教程手册和154页的Linux笔记。
回复关键词 「Python进阶」,即可获取 106 页 Python 进阶文档 PDF
回复关键词 「Python面试题」,即可获取最新 100道 面试题 PDF
回复关键词 「python数据分析」,即可获取47页python数据分析与自然语言处理的 PDF
回复关键词 「python爬虫」,满满五份PPT爬虫教程和70多个案例
回复关键词 「Python最强基础学习文档」,即可获取 168 页 Python 最强基础学习文档 PDF,让你快速入门Python
回复关键词 「linux」,即可获取 185 页 Linux 工具快速教程手册和154页的Linux笔记。
回复关键词 「Python进阶」,即可获取 106 页 Python 进阶文档 PDF
回复关键词 「Python面试题」,即可获取最新 100道 面试题 PDF
回复关键词 「python数据分析」,即可获取47页python数据分析与自然语言处理的 PDF
回复关键词 「python爬虫」,满满五份PPT爬虫教程和70多个案例
![](https://filescdn.proginn.com/f283b9be153dd54c087f04017b47999b/fd9b214e9627f543e74bb59d29cc78f4.webp)
推荐我的微信号
来围观我的朋友圈,我的经验分享,技术更新,不定期送书,坑位有限,速速扫码添加!
备注:开发方向_昵称_城市,另送你10本Python电子书。
![](https://filescdn.proginn.com/d6f76330ab8e3217b90374cb31c0da73/0a3e05d64ef8d5636d297af8713357d6.webp)
点个在看你最好看
![](https://filescdn.proginn.com/77fe49d623022252022101230f991f3d/f6f897c00e9903af7760e9690d6c4aeb.webp)
评论