python - 如何在 python 中使用这些数据绘制图表?
问题描述
我想使用一年中每个月的最高、最低和平均温度创建时间序列图。
解决方案
我建议查看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()
推荐阅读
- swift - Venmo 深度链接
- c# - 捕获线程中抛出的异常
- python - 在没有 conda 的情况下安装 gdcm
- apache-spark - 在 Spark Dataframe Java API (spark v2.3.0) 中执行相关标量子查询
- python - 创建多年的月均值列
- spring-boot - 无法使用 Spring Boot 运行此 JPA 代码
- java - 简单登录系统的时序图
- codenameone - 选择时如何设置文本字段提示的字体
- twitter-bootstrap - 如何延迟加载第 3 方视频(通过 javascript 提供)
- java - 如何在 JOOQ 中使用普通 SQL 作为派生表?