沿轴标记,matplotlib

Labeling along the axes, matplotlib

如何在图表中放置坐标轴的标签?

现在我有这个:

我想要图表内部沿轴的编号。

谢谢, 克鲁

查看 matplotlib spine placement demo,您会发现可以使用 ax.spines['left'].set_position('zero') 移动书脊。

import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns

x = np.linspace(-3,3)
y = x**2

fig, ax = plt.subplots()
ax.set_ylim(-4,10)
ax.set_xlim(-10,10)
ax.plot(x, y)
ax.spines['left'].set_position('zero')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('zero')
ax.spines['top'].set_color('none')

plt.show()