# 如何删除Matplotlib轴的一部分

Sam Sirmaxford：

``````import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0.1,1.1,step=0.1)
y = np.array([0.03,0.03,0.05,0.05,0.06,0.17,0.44,1.37,4.43,6.89])
err = np.array([0.02,0.03,0.05,0.06,0.07,0.23,3.61,4.70,1.2,0.7])

fig, ax = plt.subplots(figsize=(10,8))

ax.errorbar(x,y,yerr=err)

ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.spines['bottom'].set_position(('axes',-0.02))
ax.spines['left'].set_position(('axes',-0.02))

ax.set_xticks(np.arange(0.0,1.21,0.2))
ax.set_yticks(np.arange(0,11,2))

ax.set_xlabel('X')
ax.set_ylabel('Y')

plt.show()
``````

``````import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0.1,1.1,step=0.1)
y = np.array([0.03,0.03,0.05,0.05,0.06,0.17,0.44,1.37,4.43,6.89])
err = np.array([0.02,0.03,0.05,0.06,0.07,0.23,3.61,4.70,1.2,0.7])
fig, ax = plt.subplots(figsize=(10,8))

ax.errorbar(x,y,yerr=err)

ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.spines['bottom'].set_position(('axes',-0.02))
ax.spines['left'].set_bounds(0, 10)

ax.set_xticks(np.arange(0.0,1.21,0.2))
ax.set_yticks(np.arange(0,11,2))

ax.set_xlabel('X')
ax.set_ylabel('Y')
``````

0 条评论