Python 如何在同一轴上对df图中的多个图例进行排序?
我正在用以下代码绘制许多时间序列图形:Python 如何在同一轴上对df图中的多个图例进行排序?,python,pandas,matplotlib,Python,Pandas,Matplotlib,我正在用以下代码绘制许多时间序列图形: for code, data in automaticas.groupby('CODE'): fig, (ax1, ax2, ax3) = plt.subplots(3, sharex=False, sharey=False,figsize=(20, 15)) data.plot('FECHA',["TMAX_x"],kind='scatter', alpha=0.4, color='black',
for code, data in automaticas.groupby('CODE'):
fig, (ax1, ax2, ax3) = plt.subplots(3, sharex=False, sharey=False,figsize=(20, 15))
data.plot('FECHA',["TMAX_x"],kind='scatter', alpha=0.4, color='black', marker='o',facecolor='none', fontsize = 15.0,ax=ax1)
data.plot('FECHA',["TMAX_y"],alpha=1, color='darkred',fontsize = 15.0,ax=ax1,linewidth=1)
data.plot('FECHA',["TMIN_x"],kind='scatter',alpha=0.4,color='black',marker='o',facecolor='none', fontsize = 15.0,ax=ax2)
data.plot('FECHA',["TMIN_y"], alpha=1,color='navy', fontsize = 15.0,ax=ax2,linewidth=1)
data.plot('FECHA',["PPTOT"],kind='area',alpha=0.4,color='black', fontsize = 15.0,ax=ax3)
data.plot('FECHA',["PPA"],alpha=1,kind='area',color='turquoise', fontsize = 15.0,ax=ax3)
ax1.legend(["Temperatura Máxima Estacion Convencional",
"Temperatura Máxima Estacion Automática"],loc='upper right',framealpha=0.5)
ax2.legend(["Temperatura Mínima Estacion Convencional",
"Temperatura Mínima Estacion Automática"],loc='upper right',framealpha=0.5)
ax3.legend(["Precipitación Estacion Convencional",
"Precipitación Estacion Automática"],loc='upper right',framealpha=0.5)
每个轴有2个绘图。因此,我用以下代码绘制图例:
for code, data in automaticas.groupby('CODE'):
fig, (ax1, ax2, ax3) = plt.subplots(3, sharex=False, sharey=False,figsize=(20, 15))
data.plot('FECHA',["TMAX_x"],kind='scatter', alpha=0.4, color='black', marker='o',facecolor='none', fontsize = 15.0,ax=ax1)
data.plot('FECHA',["TMAX_y"],alpha=1, color='darkred',fontsize = 15.0,ax=ax1,linewidth=1)
data.plot('FECHA',["TMIN_x"],kind='scatter',alpha=0.4,color='black',marker='o',facecolor='none', fontsize = 15.0,ax=ax2)
data.plot('FECHA',["TMIN_y"], alpha=1,color='navy', fontsize = 15.0,ax=ax2,linewidth=1)
data.plot('FECHA',["PPTOT"],kind='area',alpha=0.4,color='black', fontsize = 15.0,ax=ax3)
data.plot('FECHA',["PPA"],alpha=1,kind='area',color='turquoise', fontsize = 15.0,ax=ax3)
ax1.legend(["Temperatura Máxima Estacion Convencional",
"Temperatura Máxima Estacion Automática"],loc='upper right',framealpha=0.5)
ax2.legend(["Temperatura Mínima Estacion Convencional",
"Temperatura Mínima Estacion Automática"],loc='upper right',framealpha=0.5)
ax3.legend(["Precipitación Estacion Convencional",
"Precipitación Estacion Automática"],loc='upper right',framealpha=0.5)
但在ax3中,排序是不正确的。所以我试了一下:
ax3.legend([data['PPA'],data['PPTOT']],["Precipitación Estacion Convencional",
"Precipitación Estacion Automática"],loc='upper right',framealpha=0.5)
但我收到了此警告,并且代码没有在ax3中绘制图例:
A proxy artist may be used instead.
See: https://matplotlib.org/users/legend_guide.html#creating-artists-specifically-for-adding-to-the-legend-aka-proxy-artists
__main__:407: UserWarning: Legend does not support 185245 0.0
你介意帮我吗