matplotlib绘制散点图代码示例(知识点plt.scatter)

代码如下:

# -*-coding:utf-8-*-

#@Author: Songzq

#@Time: 2019年07月18日06时

#说明:

#总结:

import matplotlib.pyplot as plt  #导入matplotlib.pyplot库

#2019年4月份最高每日最高温度

y_april_high = [16,19,21,28,21,20,19,17,9,18,19,22,23,23,26,26,28,24,17,15,22,26,28,19,18,21,16,19,23,24]

#2019年4月份最高每日最低温度

y_april_lower = [4,3,6,9,8,6,7,4,2,9,6,9,7,8,11,12,16,10,10,8,8,15,15,9,8,10,6,9,13,13]

#2019年6月份最高每日最高温度

y_june_high = [ 30,32,34,28,31,26,31,34,31,33,32,33,29,35,32,25,29,33,33,36,32,34,35,36,36,35,33,32,35,32]

#2019年6月份最高每日最低温度

y_june_lower = [18,19,20,19,19,18,21,20,18,18,20,22,20,20,19,18,20,22,22,23,21,22,23,24,24,22,23,22,23,21]

x_apirl_days = range(1,31)

x_june_days = range(52,82)

#设置图形大小

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

#使用scatter方法绘制散点图,plot方法是绘制折线图

plt.scatter(x_apirl_days, y_april_high,label="Apirl High")

plt.scatter(x_apirl_days,y_april_lower,label="Apirl Lower")

plt.scatter(x_june_days, y_june_high,label="June High")

plt.scatter(x_june_days,y_june_lower,label="June High")

#调整x轴的刻度

_x_days = list(x_apirl_days) + list(x_june_days)

_xtick_labels = ["Apirl {}".format(i) for i in x_apirl_days]

_xtick_labels += ["June {}".format(i-51) for i in x_june_days]

plt.xticks(list(_x_days)[::2],list(_xtick_labels)[::2],rotation=45)

#添加图例

plt.figlegend(loc="upper left")

#添加描述信息

plt.xlabel("Time")

plt.ylabel("Temperature")

plt.title("Weather")

#展示

plt.show()

输出图形:


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,448评论 0 10
  • 此系类为PHP后台开发的笔记 备注:此次是以实战为主(跟着视频学习,所以更加实用,当然也会忽略许多的细节) 1.A...
    fangtang0101阅读 179评论 0 0
  • zhazhaK丶阅读 156评论 0 3
  • 习惯 每个人都有属于自己特有的习惯。大部分习惯是无意间养成的,也有少部分是刻意养成的。当某种行为成为习惯时...
    782c6a7ad1f5阅读 333评论 0 2
  • 淡墨青衫jing阅读 206评论 0 3