【发布时间】:2016-03-08 02:02:10
【问题描述】:
我找到了一个带有锤子投影的人物,我一直在尝试复制它。 Hammer 投影本身没有问题,但我不知道如何生成地图下方的轴。事实上,我不知道如何在图形之外绘制(箭头和文本)一些东西。任何人都可以提供一个想法如何复制带有底部轴的图形吗?
【问题讨论】:
标签: matplotlib axes
我找到了一个带有锤子投影的人物,我一直在尝试复制它。 Hammer 投影本身没有问题,但我不知道如何生成地图下方的轴。事实上,我不知道如何在图形之外绘制(箭头和文本)一些东西。任何人都可以提供一个想法如何复制带有底部轴的图形吗?
【问题讨论】:
标签: matplotlib axes
你不能在图形坐标(像素或分数)中使用注释(参见http://matplotlib.org/users/annotations_intro.html)吗?
【讨论】:
【讨论】:
fig = plt.figure() rect = 0.05,0.05,0.9,0.9 ax = fig.add_axes(rect) m = Basemap(projection='hammer',lon_0=0,resolution='c') m.drawparallels(np.arange(-90.,120.,30.)) ax.text(0, 0, '180$^\circ$', ha='left', transform=ax.transAxes) ax.arrow(0.05, 0.0, 0.1, 0, head_width=0.05, head_length=0.05, fc='k', ec='k',transform=ax.transAxes)
ax=fig.add_axes([0.2, 0.2, 0.6, 0.6]) 在轴的每一侧为您提供 1/5 (=0.2) 的图形大小的空白。这应该为您的旁注提供足够的空间。
from mpl_toolkits.basemap import Basemap import numpy as np import matplotlib.pyplot as plt fig = plt.figure() ax1 = fig.add_axes([0.2,0.2,0.6,0.6]) m = Basemap(projection='hammer',lon_0=0,resolution='c') # draw parallels and meridians. m.drawparallels(np.arange(-90.,120.,30.)) m.drawmeridians(np.arange(0.,420.,60.)) ax1.arrow(0, 0, 0.5, 0, head_width=0.05, head_length=0.05, fc='k', ec='k',transform=ax1.transAxes) plt.show()你能试试看吗?
mpl_toolkits.basemap,也不会。我不明白,你如何将Basemap 与ax1 联系起来。也许在Basemap 文档中寻找一些关键字参数,以在ax 上显式绘制它。
我的解决方案,以上述为基础:
我用弧度来标记我的坐标轴,并且使用的是极坐标系,但原理是一样的:
# custom x-axis
ax.text(.49, -.15, '0', ha='left', transform=ax.transAxes)
ax.text(.24, -.15, r'$\frac{\pi}{2}$', ha='left', transform=ax.transAxes)
ax.text(0, -.15, r"$\pi$", ha='left', transform=ax.transAxes)
ax.text(.74, -.15, r"$\frac{3\pi}{2}$", ha='left', transform=ax.transAxes)
ax.text(.98, -.15, r"$\pi$", ha='left', transform=ax.transAxes)
ax.annotate('', xy=(.96, -.1275), xycoords='axes fraction', xytext=(.78, -.1275),
arrowprops=dict(arrowstyle="<-", alpha=.35))
ax.annotate('', xy=(.72, -.1275), xycoords='axes fraction', xytext=(.52, -.1275),
arrowprops=dict(arrowstyle="<-", alpha=.35))
ax.annotate('', xy=(.48, -.1275), xycoords='axes fraction', xytext=(.27, -.1275),
arrowprops=dict(arrowstyle="<-", alpha=.35))
ax.annotate('', xy=(.23, -.1275), xycoords='axes fraction', xytext=(.03, -.1275),
arrowprops=dict(arrowstyle="<-", alpha=.35))
# custom y-axis
ax.text(.84, .98, '0', ha='left', transform=ax.transAxes)
ax.text(.84, -.03, r"$\pi$", ha='left', transform=ax.transAxes)
ax.annotate('', xy=(.85, .12), xycoords='axes fraction', xytext=(.85, .01),
arrowprops=dict(arrowstyle="<-", alpha=.35))
ax.annotate('', xy=(.851, .97), xycoords='axes fraction', xytext=(.851, .87),
arrowprops=dict(arrowstyle="-", alpha=.35))
【讨论】: