The problem comes with the use of a jupyter notebook and its inline backend. So you will get the correct output if using the %matplotlib notebook
backend. (You need to restart the kernel for that.)
%matplotlib notebook
from mpl_toolkits.axisartist.axislines import SubplotZero
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(1)
ax = SubplotZero(fig, 111)
fig.add_subplot(ax)
for direction in ["xzero", "yzero"]:
# adds arrows at the ends of each axis
ax.axis[direction].set_axisline_style("-|>", size=5)
# adds X and Y-axis from the origin
ax.axis[direction].set_visible(True)
for direction in ["left", "right", "bottom", "top"]:
# hides borders
ax.axis[direction].set_visible(False)
x = np.linspace(-0.5, 1., 100)
ax.plot(x, np.sin(x*np.pi))
plt.show()

If you want /need to use the %matplotlib inline
backend, you may need to revert some of the settings, such that the arrows are not cropped from the figure.
The default setting for creating the png figure is the use of the bbox_inches="tight"
option. This can be reverted via
%config InlineBackend.print_figure_kwargs = {'bbox_inches':None}
The default figure size, dpi and subplot parameters are different. Reverting those can be done via
plt.rcdefaults()
Due to a bug in Iypthon the rcParameters should not be set in the first cell of the notebook.
Hence
# Cell 1
%matplotlib inline
%config InlineBackend.print_figure_kwargs = {'bbox_inches':None}
# Cell 2
import matplotlib.pyplot as plt
plt.rcdefaults()
from mpl_toolkits.axisartist.axislines import SubplotZero
import numpy as np
fig = plt.figure(1)
ax = SubplotZero(fig, 111)
fig.add_subplot(ax)
for direction in ["xzero", "yzero"]:
# adds arrows at the ends of each axis
ax.axis[direction].set_axisline_style("-|>", size=5)
# adds X and Y-axis from the origin
ax.axis[direction].set_visible(True)
for direction in ["left", "right", "bottom", "top"]:
# hides borders
ax.axis[direction].set_visible(False)
x = np.linspace(-0.5, 1., 100)
ax.plot(x, np.sin(x*np.pi))
plt.show()
