python plt 如何画不同的数据图

参考网址:

https://matplotlib.org/examples/pylab_examples/subplots_demo.html

https://stackoverflow.com/questions/24793241/2-subplots-sharing-y-axis-no-space-between-with-single-color-bar


 

 

sharing y axis

import numpy
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable

#Random data
data = numpy.random.random((10, 10))

fig = plt.figure()

ax1 = fig.add_subplot(1,2,1, aspect = "equal")
ax2 = fig.add_subplot(1,2,2, aspect = "equal", sharey = ax1)  #Share y-axes with subplot 1

#Set y-ticks of subplot 2 invisible
plt.setp(ax2.get_yticklabels(), visible=False)

#Plot data
im1 = ax1.pcolormesh(data)
im2 = ax2.pcolormesh(data)

#Define locations of colorbars for both subplot 1 and 2
divider1 = make_axes_locatable(ax1)
cax1 = divider1.append_axes("right", size="5%", pad=0.05)

divider2 = make_axes_locatable(ax2)
cax2 = divider2.append_axes("right", size="5%", pad=0.05)

#Create and remove the colorbar for the first subplot
cbar1 = fig.colorbar(im1, cax = cax1)
fig.delaxes(fig.axes[2])

#Create second colorbar
cbar2 = fig.colorbar(im2, cax = cax2)

#Adjust the widths between the subplots
plt.subplots_adjust(wspace = -.059)

plt.show()

 

转载于:https://www.cnblogs.com/hwy89289709/p/6943336.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值