目录
画图
横坐标添加月份
Python
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
# 准备时间和温度数据
start_date = pd.to_datetime('1996-12-01') # the next date
end_date = pd.to_datetime('1998-12-01') # the current data, so 36
time_index = pd.date_range(start_date, end_date, freq='M')
temperature_data = np.random.uniform(0, 40, len(time_index)) # 这里使用随机温度数据,您应该替换为您的实际数据
print("shape:",temperature_data.shape)
# 创建时间序列图
plt.figure(figsize=(12, 6))
plt.plot(time_index, temperature_data, marker='o', linestyle='-')
plt.title('Temperature-Time-Series')
plt.xlabel('Time')
plt.ylabel('Temperature')
plt.xticks(rotation=45) # 旋转x轴标签以包含月份
plt.grid(True)
plt.show()
Matlab
startYear = 2023;startMonth=1;endYear=2023;endMonth=12;
time_index = datetime(startYear,startMonth, 1):calmonths(1):datetime(endYear,endMonth, 1);
plot(time_index,rand(length(time_index),1));
标签:11,25,plt,index,Python,datetime,pd,time,date
From: https://www.cnblogs.com/memokeerbisi/p/18446018