Reputation: 2506
I have the following plot:
I want to move the y axis to x = 0 with ticks and everything, how can I do it?
Upvotes: 4
Views: 20195
Reputation: 1183
Here you go
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
x = np.linspace(-np.pi, np.pi, 100)
y = 2*np.sin(x)
ax = fig.add_subplot(111)
ax.set_title('centered spines')
ax.plot(x, y)
ax.spines['left'].set_position('center')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('bottom')
ax.spines['top'].set_color('none')
ax.spines['left'].set_smart_bounds(True)
ax.spines['bottom'].set_smart_bounds(True)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
more examples:http://matplotlib.org/examples/pylab_examples/spine_placement_demo.html
Upvotes: 4