Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 绘制不同小时时间序列的子地块:绘制每个小时子地块的日平均值_Python_Matplotlib_Time Series - Fatal编程技术网

Python 绘制不同小时时间序列的子地块:绘制每个小时子地块的日平均值

Python 绘制不同小时时间序列的子地块:绘制每个小时子地块的日平均值,python,matplotlib,time-series,Python,Matplotlib,Time Series,我有一个数据框架,每小时测量一年6个不同的气象变量。我尝试创建子地块,显示同一子地块中每个气象数据的小时和日平均值。然而,我没有接近 通过这个,我得到了每个变量的子批次: sns.set(style = "white", palette = "Dark2") yaxis_titles = ['Global Irradiance $(W/m^2)$', 'Precipitation (-)', 'Relative Humidity (%)', 'Ambien

我有一个数据框架,每小时测量一年6个不同的气象变量。我尝试创建子地块,显示同一子地块中每个气象数据的小时和日平均值。然而,我没有接近

通过这个,我得到了每个变量的子批次:

sns.set(style = "white", palette = "Dark2")
yaxis_titles = ['Global Irradiance $(W/m^2)$', 'Precipitation (-)', 'Relative Humidity (%)', 'Ambient temperature (°C)', 'Wind speed (m/s)', 'Wind speed direction (°)']
axes = meteo.plot( figsize=(12, 20), subplots=True, sharex = True, title = yaxis_titles)
我曾经尝试过这样做,这会让我对我想要的东西进行排序,但是由于我正在为每个循环创建一个绘图,所以我不确定如何使它们共享x轴,这样就不会导致冗长

fig, ax = plt.subplots(1, len(meteo.columns), sharex=True, tight_layout=True)

for i in range(len(meteo.columns)):
    s = 611+i 
    ax = plt.subplot(s) # s= nrows, ncols, index
    meteo[meteo.columns[i]].plot(title = yaxis_titles[i], label = "Hourly")
    meteo[meteo.columns[i]].resample("D").mean().plot(title = yaxis_titles[i], ax= ax, label = "Daily average")
谁能给我指一下正确的方向吗?谢谢大家!

编辑:

我已经找到了一种方法,但它还不是完美的,因为传说中的说法是不正确的。事实上,我更愿意根本不显示它们,或者只是能够指出“黑色”--“线是日平均值

import matplotlib.lines as mlines

yaxis_titles = ['Global Irradiance $(W/m^2)$', 'Precipitation (-)', 'Relative Humidity (%)', 'Ambient temperature (°C)', 'Wind speed (m/s)', 'Wind speed direction (°)']

meteo_mean = meteocorrect.resample("D").mean()

hourly = meteo.plot(figsize=(12, 20), subplots=True, sharex = True, title = yaxis_titles, label = None)
daily = meteo_mean.plot(subplots = True, ax = hourly, color='black', style = "--", label = None);
black_line = mlines.Line2D([], [], color='black',
                          markersize=15, label='Daily Average')
plt.legend(handles=[black_line]);
它给出了如下内容:


问题是“黑线”并没有使它变成虚线,即使我在子图中设置了legend=None,它们仍然会出现。

我想你已经接近了。我能看到的主要问题是,您没有直接使用在循环之前创建的Axis对象

我将直接循环这些列和数据帧列,并始终将Axis对象传递给数据帧的
plot
方法

fig,axes=plt.子图(len(meteo.columns),1,sharex=True,tight_layout=True)
对于ax、col、zip中的标题(axs.flat、meteo.columns、yaxis_title):
meteo.loc[:,col].绘图(title=title,label=“Hourly”,ax=ax)
meteo.loc[:,col]。重新采样(“D”).mean().plot(title=titles,ax=ax,label=“每日平均值”)

YEEEEIH,非常感谢!我挣扎了很多!!