fig, axes = plt.subplots(3, 3, figsize=(6,6))
for i, row in enumerate(axes):
for j, col in enumerate(row):
col.imshow(np.arange(100).reshape((10,10)))
col.set_xlabel('x')
col.set_ylabel('y')
plt.tight_layout()
fig, axes = plt.subplots(3, 3, figsize=(6,6))
for i, row in enumerate(axes):
for j, col in enumerate(row):
col.imshow(np.arange(100).reshape((10,10)))
if col.is_last_row():
col.set_xlabel('x')
if col.is_first_col():
col.set_ylabel('y')
plt.tight_layout()
fig, axes = plt.subplots(3, 3, figsize=(6,6))
for i, row in enumerate(axes):
for j, col in enumerate(row):
col.imshow(np.arange(100).reshape((10,10)))
fig.text(0.5, 0, 'x', ha='center')
fig.text(0, 0.5, 'y', va='center', rotation='vertical')
plt.tight_layout()
fig, axes = plt.subplots(3, 3, sharex=True, sharey=True, figsize=(6,6))
for i, row in enumerate(axes):
for j, col in enumerate(row):
col.imshow(np.arange(100).reshape((10,10)))
fig.text(0.5, 0, 'x', ha='center')
fig.text(0, 0.5, 'y', va='center', rotation='vertical')
plt.tight_layout()
fig, axes = plt.subplots(3, 3, sharex=True, sharey=True, figsize=(6,6))
for i, row in enumerate(axes):
for j, col in enumerate(row):
col.imshow(np.arange(100).reshape((10,10)))
if col.is_last_row():
col.set_xlabel('x')
if col.is_first_col():
col.set_ylabel('y')
plt.tight_layout()
fig, axes = plt.subplots(3, 3, sharex=True, sharey=True, figsize=(6,6))
for i, row in enumerate(axes):
for j, col in enumerate(row):
im = col.imshow(np.arange(100).reshape((10,10)))
ax_cb = fig.colorbar(im, ax=col)
if col.is_last_row():
col.set_xlabel('x')
if col.is_first_col():
col.set_ylabel('y')
plt.tight_layout()
fig, axes = plt.subplots(3, 3, sharex=True, sharey=True, figsize=(6,6))
fig.subplots_adjust(wspace = .1,hspace = 0)
for i, row in enumerate(axes):
for j, col in enumerate(row):
im = col.imshow(np.arange(100).reshape((10,10)))
# ax_cb = fig.colorbar(im, ax=col)
if col.is_last_row():
col.set_xlabel('x')
if col.is_first_col():
col.set_ylabel('y')
cb = fig.colorbar(im, ax=axes.ravel().tolist())
cb.ax.tick_params()
cb.set_label("colorbar")
# plt.tight_layout() # 使用 tight layout 需要手动调整 colorbar 位置,否则会很难看
plt.show()
fig, axes = plt.subplots(3, 3, sharex=True, sharey=True, figsize=(6,6))
fig.subplots_adjust(wspace = 0,hspace = 0.1)
for i, row in enumerate(axes):
for j, col in enumerate(row):
im = col.imshow(np.arange(100).reshape((10,10)))
# ax_cb = fig.colorbar(im, ax=col)
if col.is_last_row():
col.set_xlabel('x')
if col.is_first_col():
col.set_ylabel('y')
cb = fig.colorbar(im, ax=axes.ravel().tolist(),orientation='horizontal')
cb.ax.tick_params()
cb.set_label("colorbar")
# plt.tight_layout() # 使用 tight layout 需要手动调整 colorbar 位置,否则会很难看
plt.show()
fig, axes = plt.subplots(3, 3, sharex=True, sharey=True, figsize=(6,5))
fig.subplots_adjust(wspace = .1,hspace = 0)
for i, row in enumerate(axes):
for j, col in enumerate(row):
im = col.imshow(np.arange(100).reshape((10,10)))
# ax_cb = fig.colorbar(im, ax=col)
if col.is_last_row():
col.set_xlabel('x')
if col.is_first_col():
col.set_ylabel('y')
fig.subplots_adjust(bottom=0, right=0.9, top=1)
cax = plt.axes([0.92, 0.03, 0.03, 0.95])
cb = fig.colorbar(im, cax=cax)
cb.ax.tick_params()
cb.set_label('colorbar')
# plt.tight_layout() # 使用 tight layout 需要手动调整 colorbar 位置,否则会很难看
plt.show()
fig, axes = plt.subplots(3, 3, sharex=True, sharey=True, figsize=(6,5))
fig.subplots_adjust(wspace = .1,hspace = 0)
for i, row in enumerate(axes):
for j, col in enumerate(row):
im = col.imshow(np.arange(100).reshape((10,10)))
# ax_cb = fig.colorbar(im, ax=col)
if col.is_last_row():
col.set_xlabel('x')
if col.is_first_col():
col.set_ylabel('y')
col.set_xticks(np.arange(0, 11, 2))
col.set_yticks(np.arange(0, 11, 2))
col.set_xticklabels(np.arange(1, 11, 2))
col.set_yticklabels(np.arange(1, 11, 2))
fig.subplots_adjust(bottom=0, right=0.9, top=1)
cax = plt.axes([0.92, 0.03, 0.03, 0.95])
cb = fig.colorbar(im, cax=cax)
cb.ax.tick_params()
cb.set_label('colorbar')
# plt.tight_layout() # 使用 tight layout 需要手动调整 colorbar 位置,否则会很难看
plt.show()
fig, ax = plt.subplots(figsize=(6,4))
t = np.linspace(0, 2*np.pi, 50, endpoint=False)
sins = np.sin(t)
coss = np.cos(t)
ax.plot(t, sins, 'r', alpha=0.5, lw=0.5, ls='-', marker='+', label='sin')
ax2 = ax.twinx()
ax2.plot(t, coss, 'g', alpha=0.5, lw=0.5, ls='-', marker='+', label='cos')
for tl in ax2.get_yticklabels():
tl.set_color("r")
plt.tight_layout()