使用 matplotlib 创建在线图上的散点图
Create scatterplot over line plot with matplotlib
所以我对 python 很陌生,我必须在我已经使用气候数据制作的线图之上创建一个 散点图 。我已经有了散点图的数据框,其中包含 1837 年到 2020 年期间某个站点的月平均温度。
线图显示了三个图表,描述了这段时间的平均温度、最低温度和最高温度,x 轴显示月份,y 轴显示温度(以摄氏度为单位)。
任何人都可以帮助我使用哪些代码将散点图添加到折线图之上?
(我猜测使用 plt.scatter())
您需要在同一张图上绘制散点图和线图,如下所示:
import random
import matplotlib.pyplot as plt
fig= plt.figure(figsize=(4, 3))
ax = plt.axes()
ax.scatter([random.randint(1, 200) for i in range(100)],
[random.randint(1, 200) for i in range(100)])
ax.plot([1, 200], [1,200])
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title('Scatter and Line plots')
plt.show()
这又会 return 下图:
所以我对 python 很陌生,我必须在我已经使用气候数据制作的线图之上创建一个 散点图 。我已经有了散点图的数据框,其中包含 1837 年到 2020 年期间某个站点的月平均温度。 线图显示了三个图表,描述了这段时间的平均温度、最低温度和最高温度,x 轴显示月份,y 轴显示温度(以摄氏度为单位)。 任何人都可以帮助我使用哪些代码将散点图添加到折线图之上? (我猜测使用 plt.scatter())
您需要在同一张图上绘制散点图和线图,如下所示:
import random
import matplotlib.pyplot as plt
fig= plt.figure(figsize=(4, 3))
ax = plt.axes()
ax.scatter([random.randint(1, 200) for i in range(100)],
[random.randint(1, 200) for i in range(100)])
ax.plot([1, 200], [1,200])
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title('Scatter and Line plots')
plt.show()
这又会 return 下图: