首页 > 解决方案 > 如何在 python 中使用这些数据绘制图表?

问题描述

我想使用一年中每个月的最高、最低和平均温度创建时间序列图。

标签: pythonplotgraph

解决方案


我建议查看matplotlib以可视化不同类型的数据,这些数据可以通过快速pip3 install matplotlib.

以下是一些您可以尝试熟悉该库的入门代码:

# Import the library
import matplotlib.pyplot as plt

# Some sample data to play around with
temps = [30,40,45,50,55,60]
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]

# Create a figure and plot the data
plt.figure()
plt.plot(temps)

# Add labels to the data points (optional)
for i, point in enumerate(months):
    plt.annotate(point, (i, temps[i]))

# Apply some labels
plt.ylabel("Temperature (F)")
plt.title("Temperature Plot")

# Hide the x axis labels 
plt.gca().axes.get_xaxis().set_visible(False)

# Show the comlpeted plot
plt.show()

推荐阅读