小编Sum*_*mit的帖子

How to adjust size of two subplots, one with colorbar and another without, in pyplot ?

Consider this example

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

plt.subplot(121)
img = plt.imshow([np.arange(0,1,.1)],aspect="auto")
ax = plt.gca()
divider = make_axes_locatable(ax)
cax = divider.append_axes("bottom", size="3%", pad=0.5)
plt.colorbar(img, cax=cax, orientation='horizontal')
plt.subplot(122)
plt.plot(range(2))
plt.show()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明 I want to make these two figures (plot region without colorbar) of the same size.

The size is automatically adjusted if the colorbar is plotted vertically or if two rows are used (211, 212) instead of two columns.

python matplotlib

2
推荐指数
2
解决办法
2110
查看次数

标签 统计

matplotlib ×1

python ×1