Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

第 14 章 数据可视化

目录

14.1. matplotlib
14.1.1. 直方图
14.1.2. 显示中文
14.2. pyecharts

14.1. matplotlib

14.1.1. 直方图

		
import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_excel("data1.xlsx", "Sheet1")

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.hist(df['年龄'], bins=7)
plt.title('Age distribution')
plt.xlabel('Age')
plt.ylabel('Employee')
plt.show()
		
		
		

14.1.2. 显示中文

		
import matplotlib.pyplot as plt
import pandas as pd
from matplotlib.font_manager import FontProperties

title = FontProperties(fname=r"/System/Library/Fonts/PingFang.ttc", size=14)
font = FontProperties(fname=r"/System/Library/Fonts/PingFang.ttc", size=10)

df = pd.read_excel("data.xlsx", "Sheet1")

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.hist(df['年龄'], bins=7)
plt.title('年龄分布图', fontproperties=title)
plt.xlabel('年龄', fontproperties=font)
plt.ylabel('员工数量', fontproperties=font)
plt.show()