I want to change the location of the axes spines of a matplotlib plot (e.g., 'left') to a specific data value. I am aware that I can use matplotlib.spines.set_position() to this end, and on a linear plot this works fine. However, on a log (or, semi-log) plot the axis is not showing for some reason. The following code and screenshot demonstrate the problem: demo spine position on log plot
# test axis location on log plot
from matplotlib import pyplot as plt
figure = plt.figure()
axes = figure.add_subplot(121)
handle, = axes.plot([0.2, 1], [1, 2], 'ro')
axes.xaxis.set_label_text('X')
axes.yaxis.set_label_text('Y')
axes.set_xscale('log')
axes.set_xlim(0.02, 2)
axes.spines['left'].set_position(('data', 0.1))
axes.spines['left'].set_linewidth(3)
axes.set_title('log')
axes2 = figure.add_subplot(122)
handle2, = axes2.plot([0.2, 1], [1, 2], 'ro')
axes2.xaxis.set_label_text('X')
axes2.yaxis.set_label_text('Y')
axes2.set_xlim(0, 2)
axes2.spines['left'].set_position(('data', 0.5))
axes2.spines['left'].set_linewidth(3)
axes2.set_title('linear')
plt.show()
In the left, semi-log plot, the 'left' spine is no longer showing at all, whereas it does show up at the correct location in the right-hand, linear plot. As a workaround, I can convert the data coordinates to axes coordinates and then use set_position(('axes', xxx)), where xxx refers to the converted coordinate. However, to allow dynamic zooming and rescaling of the plot, I'd much rather set the spine to a specific data value, rather than an axis value.
I am using matplotlib v 3.0.2 and Python 3.6 on a Windows platform. This question appears related to (yet distinct from): Positions of spines in matplotlib Setting spines in matplotlibrc