栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python数据可视化 -- matplotlib与pyecharts的使用

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python数据可视化 -- matplotlib与pyecharts的使用

matplotlib:https://www.matplotlib.org.cn/

pyecharts:https://pyecharts.org/#/zh-cn/intro

折线图

一周温度变化折线图

matplotlib
import matplotlib.pyplot as plt

# 设置字体
plt.rcParams["font.sans-serif"] = ["SimHei"]

# 生成温度数据
values = [10, 30, 25, 30, 40, 30, 27]
label = [f'星期{i}' for i in '一二三四五六日']
plt.plot(label, values)
plt.title("一周温度变化")
# 将数值格式化成摄氏度
plt.yticks(values, list(map(lambda x: f'{x}°', values)))
plt.show()

pyecharts
from pyecharts.charts import Line
import pyecharts.options as opts

# 生成温度数据
values = [10, 30, 25, 30, 40, 30, 27]
label = [f'星期{i}' for i in '一二三四五六日']
Line().add_xaxis(label).add_yaxis("温度", values) 
    .set_global_opts(title_opts=opts.TitleOpts(title='一周温度变化')).render()

柱形图

部分城市平均工资

matplotlib
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['SimHei']

salarys = [166803, 149377, 137310, 130155]
citys = ['北京', '上海', '深圳', '南京']
plt.bar(citys, salarys, width=0.1)
plt.show()

pyecharts
from pyecharts.charts import Bar

salarys = [166803, 149377, 137310, 130155]
citys = ['北京', '上海', '深圳', '南京']
Bar().add_xaxis(citys).add_yaxis("工资", salarys).render()

饼图

员工学历情况

matplotlib
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['SimHei']

salarys = [14, 20, 30, 20]
citys = ['本科', '专科', '研究生', '其他']
plt.pie(salarys, labels=citys)
plt.show()

pyecharts
from pyecharts.charts import Pie
from collections import Counter

citys = ['本科', '专科', '研究生', '其他', '本科', '专科', '研究生', '其他', '本科', '专科', '研究生', '其他']
Pie().add("员工学历情况", Counter(citys).most_common()).render()

词云图

城市词云图

wordcloud
from wordcloud import WordCloud

citys = ["北京", "上海", "广州", "南京", "上海", "广州", "南京", "广州", "南京", '长沙']

w = WordCloud(font_path='simhei.ttf', background_color='white')
w.generate(" ".join(citys))
w.to_file('abc.png')

pyecharts
from pyecharts.charts import WordCloud
from collections import Counter

citys = ["北京", "上海", "广州", "南京", "上海", "广州", "南京", "广州", "南京", '长沙']

WordCloud().add("城市", Counter(citys).most_common()).render()

散点图 地图 雷达图 热力图
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/664168.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号