Pyplot move origin with axis
<p>I have some code for a plot I want to create:</p>

<pre><code>import numpy as np
import matplotlib.pyplot as plt

# data
X = np.linspace(-1, 3, num=50, endpoint=True)
b = 2.0
Y = X + b

# plot stuff
fig = plt.figure(figsize=(8,6))
ax = fig.add_subplot(1, 1, 1)
ax.set_title('linear neuron')

# move axes
ax.spines['left'].set_position(('axes', 0.30))
# ax.spines['left'].set_smart_bounds(True)
ax.yaxis.set_ticks_position('left')

ax.spines['bottom'].set_position(('axes', 0.30))
# ax.spines['bottom'].set_smart_bounds(True)
ax.xaxis.set_ticks_position('bottom')

ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')

# title
title = ax.set_title('Linear Neuron', y=1.10)

# axis ticks
# ax.set_xticklabels([0 if item == 0 else '' for item in X])
# ax.set_yticklabels([])
# for tick in ax.xaxis.get_majorticklabels():
#   tick.set_horizontalalignment('left')
# ax.tick_params(axis=u'both', which=u'both',length=0)

# axis labels
ax.xaxis.set_label_coords(1.04, 0.30 - 0.025)
ax.yaxis.set_label_coords(0.30 - 0.03, 1.04)
y_label = ax.set_ylabel('output')
y_label.set_rotation(0)
ax.set_xlabel('input')

# ax.get_xaxis().set_visible(False)
# ax.get_yaxis().set_visible(False)

# grid
ax.grid(True)


ax.plot(X, Y, '-', linewidth=1.5)

fig.tight_layout()
fig.savefig('plot.pdf')
</code></pre>

<p>In this plot the x and y axis are moved. However, the origin is not moved with then, as one can see from the ticks and ticklabels.</p>

<p>How can I always move the origin with the x and y axis?</p>

<p>I guess it would be the same as simply looking at another area of the plot, so that the x and y axis are at the lower left but not in the corner as they usually are.</p>

<p>To visualize this:</p>

<p><a href="http://i.stack.imgur.com/l3zQp.png" rel="nofollow"><img src="http://i.stack.imgur.com/l3zQp.png" alt="current situation"></a></p>

<p>What I want:</p>

<p><a href="http://i.stack.imgur.com/J7iyT.png" rel="nofollow"><img src="http://i.stack.imgur.com/J7iyT.png" alt="enter image description here"></a></p>

<p>Where the arrow points to the x and y axis intersection, I want to have the origin, <code>(0|0)</code>. Where the dashed arrow points upwards I want the line to move upwards, so that it is still mathematically at the correct position, when the origin moves.</p>

<p><em>(the final result of the efforts can be found <a href="https://gist.github.com/ZelphirKaltstahl/270df543207174f8ed82c0970d67b62e" rel="nofollow">here</a>)</em></p>

<p>You've done a lot of manual tweaking of where each thing goes, so the solution is not very portable. But here it is: remove the <code>ax.spines['bottom'].set_position</code> and <code>ax.xaxis.set_label_coords</code> calls from your original code, and add this instead:</p>

<pre><code>ax.set_ylim(-1, 6)
ax.spines['bottom'].set_position('zero')
xlabel = ax.xaxis.get_label()
lpos = xlabel.get_position()
xlabel.set_position((1.04, lpos[1]))
</code></pre>

<p>The "bring origin up" was really accomplished by just <code>ax.set_ylim</code>, the rest is to get your labels where you want them.</p>

python matplotlib axis-labels