在将轴保持在pyplot子图中的同时移除框架 [英] Removing frame while keeping axes in pyplot subplots

查看:85
本文介绍了在将轴保持在pyplot子图中的同时移除框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个包含3个子图的图形,并且想知道是否有任何方法可以在保持轴位置的同时移除周围的框架?

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?

推荐答案

如果要删除轴的刺,而不是其他信息(刻度,标签等),则可以这样做:

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)

或更简单地使用 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:

这篇关于在将轴保持在pyplot子图中的同时移除框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆