每个子图中的matplotlib颜色条 [英] matplotlib colorbar in each subplot

查看:87
本文介绍了每个子图中的matplotlib颜色条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为2x2图中的每个子图添加一个单独的颜色条.

fig , ( (ax1,ax2) , (ax3,ax4)) = plt.subplots(2, 2,sharex = True,sharey=True)
z1_plot = ax1.scatter(x,y,c = z1,vmin=0.0,vmax=0.4)
plt.colorbar(z1_plot,cax=ax1)
z2_plot = ax2.scatter(x,y,c = z2,vmin=0.0,vmax=40)
plt.colorbar(z1_plot,cax=ax2)
z3_plot = ax3.scatter(x,y,c = z3,vmin=0.0,vmax=894)
plt.colorbar(z1_plot,cax=ax3)
z4_plot = ax4.scatter(x,y,c = z4,vmin=0.0,vmax=234324)
plt.colorbar(z1_plot,cax=ax4)
plt.show()

我认为这是您的操作方式,但结果情节确实弄得一团糟;它只有全灰色背景,并且忽略了我拥有的set_xlim和set_ylim命令(为简单起见,此处未显示). +它没有显示颜色条.这是正确的方法吗?

我还尝试摆脱了"cax = ...",但是彩条全部显示在右下角的图上,而不是每个单独的图上!

解决方案

请查看以下 matplotlib示例页面.那里显示了如何获得每个子图带有四个单独颜色条的以下图:

我希望这会有所帮助.
您可以进一步这里,在这里您可以找到matplotlib的很多功能.

I would like to add a separate colorbar to each subplot in a 2x2 plot.

fig , ( (ax1,ax2) , (ax3,ax4)) = plt.subplots(2, 2,sharex = True,sharey=True)
z1_plot = ax1.scatter(x,y,c = z1,vmin=0.0,vmax=0.4)
plt.colorbar(z1_plot,cax=ax1)
z2_plot = ax2.scatter(x,y,c = z2,vmin=0.0,vmax=40)
plt.colorbar(z1_plot,cax=ax2)
z3_plot = ax3.scatter(x,y,c = z3,vmin=0.0,vmax=894)
plt.colorbar(z1_plot,cax=ax3)
z4_plot = ax4.scatter(x,y,c = z4,vmin=0.0,vmax=234324)
plt.colorbar(z1_plot,cax=ax4)
plt.show()

I thought that this is how you do it, but the resulting plot is really messed up; it just has an all grey background and ignores the set_xlim , set_ylim commands I have (not shown here for simplicity). + it shows no color bars. Is this the right way to do it?

I also tried getting rid of the "cax = ...", but then the colorbar all goes on the bottom right plot and not to each separate plot!

解决方案

Please have a look at this matplotlib example page. There it is shown how to get the following plot with four individual colorbars for each subplot:

I hope this helps.
You can further have a look here, where you can find a lot of what you can do with matplotlib.

这篇关于每个子图中的matplotlib颜色条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆