Python数据分析 2.Matplotlib绘图—常用统计图

Python数据分析 2.Matplotlib绘图—常用统计图

1.绘制散点图

from matplotlib import pyplot as plt
from matplotlib import font_manager

my_font = font_manager.FontProperties(fname = "C:/Windows/Fonts/simhei.ttf")

y_3 = [6, 20, 7, 13, 8, 14, 6, 17, 6, 7, 9, 8, 20, 19, 17, 13, 17, 10, 12, 12]
y_10 = [25, 26, 30, 26, 13, 27, 15, 22, 23, 28, 20, 22, 28, 12, 21, 29, 14, 21, 15, 26]

x_3 = range(1,21)
x_10 = range(31,51)

plt.figure(figsize=(20,8),dpi=80)

# 使用scatter绘制散点图
plt.scatter(x_3, y_3, label="3月份")
plt.scatter(x_10, y_10, label="10月份")


_x = list(x_3)+list(x_10)
_xtick_labels = ["3月{}日".format(i) for i in range(1,21)]
_xtick_labels += ["10月{}日".format(i) for i in range(1,21)]
plt.xticks(_x[::2], _xtick_labels[::2], fontproperties = my_font, rotation = 45)

plt.xlabel("时间", fontproperties = my_font)
plt.xlabel("温度", fontproperties = my_font)
plt.title("3月与10月温度比较", fontproperties = my_font, size = 20)

plt.legend(loc="upper left", prop=my_font)

在这里插入图片描述

2.绘制条形图

from matplotlib import pyplot as plt
from matplotlib import font_manager

my_font = font_manager.FontProperties(fname = "C:/Windows/Fonts/simhei.ttf")

a = ["战狼2","速度与激情8","功夫瑜伽","西游伏妖篇","变形金刚5:\n最后的骑士","摔跤吧!爸爸","加勒比海盗5:\n死无对证","金刚:骷髅岛","极限特工:\n终极回归","生化危机6:\n终章","乘风破浪
  • 2
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值