这绝对属于比matplotlib更麻烦的一类,但现在就开始吧。另外,对于基本情况,请查看centering spines demo in the documentation。
你可以用几种不同的方法来实现这一点,但是为了获得最佳的视觉效果,请考虑以下几点。它远不是完美的,但它相当灵活:import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.patheffects
import numpy as np
def center_spines(ax=None, centerx=0, centery=0):
"""Centers the axis spines at on the axis "ax", and
places arrows at the end of the axis spines."""
if ax is None:
ax = plt.gca()
# Set the axis's spines to be centered at the given point
# (Setting all 4 spines so that the tick marks go in both directions)
ax.spines['left'].set_position(('data', centerx))
ax.spines['bottom'].set_position(('data', centery))
ax.spines['right'].set_position(('d