import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
# 准备数据
total_bill = [16.99, 10.34, 21.01, 23.68, 24.59]
tip = [1.01, 1.66, 3.55, 3.31, 3.61]
sex = ['female', 'male', 'male', 'male', 'female']
smoker = ['no', 'yes', 'yes', 'no', 'no']
size = [2, 3, 3, 2, 4]
# 将列表转变为DataFrame,csv,DataFrame
df = pd.DataFrame({'tb': total_bill, 'tip': tip, 'sex': sex, 'sm': smoker, 'size': size})
df.to_csv('tip.csv')
df2 = pd.read_csv('tip.csv')
df2.sort_values(by='tb', inplace=True)
# 折线图
plt.subplot(1, 3, 1)
plt.plot(df2['tb'], df2['tip'], c='r', marker='o')
plt.title("消费")
plt.xlabel("")
plt.ylabel("")
# plt.show()
# 柱形图
plt.subplot(1, 3, 2)
plt.bar(df2['size'], df2['tip'])
plt.title("")
plt.xlabel("")
plt.ylabel("")
# 饼图
plt.subplot(1, 3, 3)
df3 = df2.groupby('sm').size()
plt.pie(df3, labels=["", ""], autopct='%.1f%%')
plt.title("")
plt.show()



