我想将色标放置在轴内,因为科学出版物中缺少空间。inset_axes似乎是创建子轴的一个不错的选择,但是我找不到除'loc = 0,1,2,3,4'以外的其他坐标的简单放置方法:结果,色图标签位于图形之外。我想使用与ax.annotate()中的(x,y)坐标类似的工具,以实现全面定位。
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.inset_locator import inset_axes
plt.close('all')
##### build some fake data to map ##########
x = np.linspace(-0.7,0.7,num = 50)
y = np.linspace(0,1,num = 100)
ext = (x[0],x[-1],y[-1],y[0])
xx,yy = np.meshgrid(x,y,indexing = 'ij')
U = np.cos(xx**2 + yy**2)
#### build figures and axes ###########
fig, ax = plt.subplots(1,1)
fig.set_size_inches(4, 3)
#### plot ############
im = ax.imshow(U,interpolation = 'nearest', extent = ext, aspect = 'equal',vmin=0,vmax=np.amax(U))
#### insert colorbar ######
cax = inset_axes(ax,width …Run Code Online (Sandbox Code Playgroud)