chenglong0201

效果图

绘制散点图

导包

导入可视化所用的包matplotlib

  from matplotlib import pyplot as plt

导入字体

  import matplotlib
  matplotlib.rc(\'font\', family=\'MicroSoft YaHei\', weight="bold")

给x,y赋值

  x_3 = range(1, 32)
  x_10 = range(51, 82)
  y_3 = [11, 17, 16, 11, 12, 11, 12, 6, 6, 7, 8, 9, 12, 15, 14, 17, 18, 21, 16, 17, 20, 14, 15, 15, 15, 19,  21, 22, 22, 22, 23]
  y_10 = [26, 26, 28, 19, 21, 17, 16, 19, 18, 20, 20, 19, 22, 23, 17, 20, 21, 20, 22, 15, 11, 15, 5, 13, 17, 10, 11, 13, 12, 13, 6]

建造画布

  plt.figure(figsize=(25, 15), dpi=80)  # figsize(画布大小) dpi像素点

传入x,y值

  plt.scatter(x_3, y_3, label=\'三月份温度\')
  plt.scatter(x_10, y_10, label=\'十月份温度\')

设置x轴

  _x = list(x_3)+list(x_10)
  _xtick = [\'3月%s日\' % i for i in x_3]
  _xtick += [\'10月%s日\' % i for i in range(1, 32)]
  plt.xticks(_x[::3], _xtick[::3], rotation=45)

加图例

  plt.legend(loc="upper left")

加标题

  plt.xlabel(\'时间\')
  plt.ylabel(\'温度\')
  plt.title(\'三月与十月天气对比\')

保存散点图

  plt.sivefig(\'XXX.jpg\')

展示散点图

  plt.show()

分类:

技术点:

相关文章:

  • 2021-12-09
  • 2021-08-27
  • 2021-11-29
  • 2021-09-27
  • 2021-06-11
  • 2021-08-07
猜你喜欢
  • 2021-04-16
  • 2021-10-14
  • 2021-05-05
  • 2022-12-23
  • 2022-01-19
  • 2021-05-29
相关资源
相似解决方案