将特定的颜色条添加到根据第三个变量着色的4个子图中的每个子图中

时间:2019-05-16 10:39:38

标签: python matplotlib

我需要创建一个由b 4个子图组成的图形,每个子图显示x,y的颜色是第三个变量的函数。然后,我需要为每个子图添加特定的颜色条,并为颜色条指定标题。 在这里,您可以找到在Matlab上获得的最终结果:

https://pasteboard.co/IeWZ03D.jpg

这里是我用来生成没有颜色条的图形的代码:

fig = plt.figure(figsize=(11,8))
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,3)
ax4 = fig.add_subplot(2,2,4)
ax1.scatter(results['Qmean Loops (kW)'],results['eta daily (PCS)'],c=results['T ext (°C)'],s=14)
plt.tight_layout()
ax1.set_ylabel('\u03B7 Daily (-)',fontsize=14)
ax1.set_xlabel('Qmean Loops (kW)',fontsize=14)
ax2.scatter(results['Qmean Loops (kW)'],results['eta daily (PCS)'],c=results['T rit heat(°C)'],s=14)
plt.tight_layout()
ax2.set_ylabel('\u03B7 Daily (-)',fontsize=14)
ax2.set_xlabel('Qmean Loops (kW)',fontsize=14)
ax3.scatter(results['Qmean Loops (kW)'],results['eta daily (PCS)'],c=results['DT heat(°C)'],s=14)
plt.tight_layout()
ax3.set_ylabel('\u03B7 Daily (-)',fontsize=14)
ax3.set_xlabel('Qmean Loops (kW)',fontsize=14)
ax4.scatter(results['Qmean Loops (kW)'],results['eta daily (PCS)'],c=results['T mand heat(°C)'],s=14)
plt.tight_layout()
ax4.set_ylabel('\u03B7 Daily (-)',fontsize=14)
ax4.set_xlabel('Qmean Loops (kW)',fontsize=14)
fig.savefig("Daily Analysis\Efficiency vs P&T - S1.png", dpi=fig.dpi, bbox_inches='tight')
plt.close()

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

我用以下代码解决了我的问题:

fig = plt.figure(figsize=(11,8))
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,3)
ax4 = fig.add_subplot(2,2,4)
sp1 = ax1.scatter(results['Qmean Loops (kW)'],results['eta daily (PCS)'],c =results['T ext (°C)'],s=14)
clb = plt.colorbar(sp1,ax=ax1)
clb.ax.set_title('T ext (°C)')
plt.tight_layout()
ax1.set_ylabel('\u03B7 Daily (-)',fontsize=14)
ax1.set_xlabel('Qmean Loops (kW)',fontsize=14)
sp2 = ax2.scatter(results['Qmean Loops (kW)'],results['eta daily (PCS)'],c=results['T return SH (°C)'],s=14)
clb = plt.colorbar(sp2,ax=ax2)
clb.ax.set_title('T return SH (°C)')
plt.tight_layout()
ax2.set_ylabel('\u03B7 Daily (-)',fontsize=14)
ax2.set_xlabel('Qmean Loops (kW)',fontsize=14)
sp3 = ax3.scatter(results['Qmean Loops (kW)'],results['eta daily (PCS)'],c=results['DTwater SH (°C)'],s=14)
clb = plt.colorbar(sp3,ax=ax3)
clb.ax.set_title('DTwater SH (°C)')
plt.tight_layout()
ax3.set_ylabel('\u03B7 Daily (-)',fontsize=14)
ax3.set_xlabel('Qmean Loops (kW)',fontsize=14)
sp4 = ax4.scatter(results['Qmean Loops (kW)'],results['eta daily (PCS)'],c=results['T forward SH (°C)'],s=14)
clb = plt.colorbar(sp4,ax=ax4)
clb.ax.set_title('T forward SH (°C)')
plt.tight_layout()
ax4.set_ylabel('\u03B7 Daily (-)',fontsize=14)
ax4.set_xlabel('Qmean Loops (kW)',fontsize=14)
fig.savefig("Daily Analysis\Efficiency vs P&T - S1.png", dpi=fig.dpi, bbox_inches='tight')
plt.close()

您可以在此处查看最终结果: https://pasteboard.co/IeYcaOB.png

希望它会有用!