matplotlib锤子投影绘制外部地图

时间:2016-03-08 02:02:10

标签: matplotlib axes

我找到了一个用锤子投影的图形,我一直试图复制它。 Hammer投影本身不是问题,但我不知道如何在地图下方生成轴。事实上,我不知道如何绘制(箭头和文字)图形之外的东西。任何人都可以帮助了解如何使用底部的轴复制图形吗?enter image description here

3 个答案:

答案 0 :(得分:0)

你不能在图坐标(像素或分数)中使用注释(参见http://matplotlib.org/users/annotations_intro.html)吗?

答案 1 :(得分:0)

您可以使用transform关键字在轴坐标中绘制事物而不是数据坐标。如果您构建了一个轴对象axsee here)来绘制,例如您可以使用左下方的文本字符串“180°”

ax.text(0, 0, '180$^\circ$', ha='left', transform=ax.transAxes)

transform=ax.transAxes设置坐标系,以便点(0, 0)位于左下角,(1, 0)位于右下角,(1, 1)位于右上角,(0, 1)位于左下角1}}在左上角,无论轴在数据坐标中跨越哪个值。

要绘制箭头,您可以使用ax.arrow等效地使用transform关键字。

答案 2 :(得分:0)

我的解决方案,建立在上面:

我用弧度来标记我的轴并使用极坐标系,但原理是一样的:

# 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))

Output plot

相关问题