1 # 使用matplotlib.pyplot.scatter绘制散点
 2 import matplotlib.pyplot as plt
 3 from pylab import mpl
 4 
 5 # 设置默认字体,解决中文显示乱码问题
 6 mpl.rcParams['font.sans-serif'] = ['SimHei']
 7 
 8 # 画单个点
 9 plt.scatter(0, 0, s=200)  # 指定点的大小
10 
11 # 画多个点
12 x_values = [1, 2, 3, 4, 5]
13 y_squares = [1, 4, 9, 16, 25]
14 plt.scatter(x_values, y_squares, s=100)  # 指定点的大小
15 
16 # 设置图表标题
17 plt.title("平方数值表", fontsize=24)
18 
19 # 设置横、纵坐标标题
20 plt.xlabel("数值", fontsize=14)
21 plt.ylabel("平方值", fontsize=14)
22 
23 # 设置刻度标记大小
24 plt.tick_params(axis='both', labelsize=10)
25 plt.show()

运行结果:

matplotlib之scatter绘制散点

相关文章:

  • 2021-05-01
  • 2021-09-25
  • 2022-01-13
  • 2021-11-16
  • 2022-12-23
  • 2022-01-03
猜你喜欢
  • 2021-12-05
  • 2022-12-23
  • 2021-06-22
  • 2022-02-08
  • 2021-08-18
  • 2022-12-23
相关资源
相似解决方案