【发布时间】:2017-01-02 02:47:47
【问题描述】:
我想在坐标轴内放置颜色条,因为科学出版物的空间有限。 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 = '5%',height = '17%',loc = 1)
cbar = plt.colorbar(im, ax = ax,cax = cax ,format = '%.1f' ,ticks = [0,np.amax(U)])
cax = inset_axes(ax,width = '5%',height = '17%',loc = 3)
cbar = plt.colorbar(im, ax = ax,cax = cax,format = '%.1f' ,ticks = [0,np.amax(U)])
### stuff ####
fig.tight_layout()
plt.show()
问候,
【问题讨论】:
标签: python python-2.7 matplotlib