I am creating a figure with 3 subplots, and was wondering if there is any way of removing the frame around them, while keeping the axes in place?
Asked
Active
Viewed 6.0k times
4 Answers
39
If you want to remove the axis spines, but not the other information (ticks, labels, etc.), you can do that like so:
fig, ax = plt.subplots(7,1, sharex=True)
t = np.arange(0, 1, 0.01)
for i, a in enumerate(ax):
a.plot(t, np.sin((i + 1) * 2 * np.pi * t))
a.spines["top"].set_visible(False)
a.spines["right"].set_visible(False)
a.spines["bottom"].set_visible(False)
or, more easily, using seaborn:
fig, ax = plt.subplots(7,1, sharex=True)
t = np.arange(0, 1, 0.01)
for i, a in enumerate(ax):
a.plot(t, np.sin((i + 1) * 2 * np.pi * t))
seaborn.despine(left=True, bottom=True, right=True)
Both approaches will give you:

mwaskom
- 46,693
- 16
- 125
- 127
-
If you happen to have polar plots, spines are defined differently, so per http://stackoverflow.com/a/22848030/1034716 you need to do: a.spines['polar'].set_visible(False) – rocking_ellipse Jul 16 '15 at 15:30
-
In Python 3, the for loop is even simpler: ```for a in ax:``` – Douglas Adams May 19 '19 at 22:53
-
@mwaskom How would I keep the x-axis at the last subplot in the above code? – alexv Oct 31 '20 at 00:19
39
Try plt.box(on=None)
It removed only the bounding box (frame) around plot, which is what I was trying to do.
plt.axis('off')
removed tick labels and the bounding box, which wasn't what I was looking to accomplish.

Georgy
- 12,464
- 7
- 65
- 73

Ben Miller
- 391
- 3
- 5
6
You can achieve something like this with the axis('off')
method of an axis handle. Is this the kind of thing you are after? (example code below the figure).
fig, ax = plt.subplots(7,1)
t = np.arange(0, 1, 0.01)
for i, a in enumerate(ax):
a.plot(t, np.sin((i+1)*2*np.pi*t))
a.axis('off')
plt.show()

Bonlenfum
- 19,101
- 2
- 53
- 56
3
Try
ax.set_frame_on(False)
It removes the box frame around any plot, but the x and y ticks remain.

MattSt
- 1,024
- 2
- 16
- 35