2017-01-23 10 views
0

私はこのコードを少しきれいにするいくつかの方法を試みましたが、毎回失敗しました。私は単にこれをきれいにするために探しています。Matplotlibプロット - 簡略化

fig1 = plt.figure() 
ax = fig1.add_axes([0.1,0.1,0.8,0.8]) 
ax.scatter(highForecastTemp, highActTemp) 
ax.plot(x, y) 
ax.set_xlim(min(x),max(x)) 
ax.set_ylim(min(x),max(x)) 
ax.set_title('Forecast vs Actual - High Temperature') 
ax.set_xlabel('Forecasted') 
ax.set_ylabel('Actual') 
plt.show() 

fig2 = plt.figure() 
ax = fig2.add_axes([0.1,0.1,0.8,0.8]) 
ax.scatter(lowForecastTemp, lowActTemp) 
ax.plot(a, b) 
ax.set_xlim(min(a),max(a)) 
ax.set_ylim(min(a),max(a)) 
ax.set_title('Forecast vs Actual - Low Temperature') 
ax.set_xlabel('Forecasted') 
ax.set_ylabel('Actual') 
plt.show() 
+1

「クリーンアップ」とはどういう意味ですか? –

答えて

1

機能を書くのはクリーンアップすることができます:

def plot_forecast(x, y, forecast_temp, act_temp, high_low) 
    fig1 = plt.figure() 
    ax = fig1.add_axes([0.1,0.1,0.8,0.8]) 
    ax.scatter(forecast_temp, act_temp) 
    ax.plot(x, y) 
    ax.set_xlim(min(x),max(x)) 
    ax.set_ylim(min(x),max(x)) 
    ax.set_title('Forecast vs Actual - {} Temperature'.format(high_low)) 
    ax.set_xlabel('Forecasted') 
    ax.set_ylabel('Actual') 
    plt.show() 

plot_forecast(x, y, highForecastTemp, highActTemp, 'High') 
plot_forecast(a, b, lowForecastTemp, lowActTemp, 'Low') 

さて、あなたが実際にプロット間で変更値とplot_forecastを呼び出すことができます。プロットロジックをすべて複製する必要はありません。