在Pyplot子图中删除框架而保留轴线[英] Removing frame while keeping axes in pyplot subplots

本文是小编为大家收集整理的关于在Pyplot子图中删除框架而保留轴线的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在创建一个带有3个子图的人物,并且想知道是否有任何方法可以卸下周围的框架,同时将轴固定在适当的位置?

推荐答案

尝试plt.box(on=None)它删除了 图周围的边界框(帧),这是我要做的.

plt.axis('off')删除了tick标签和边界框,这不是我想要完成的.

其他推荐答案

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

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)

两种方法都会给您:

在此处输入图像说明

其他推荐答案

您可以使用轴手柄的axis('off')方法实现这样的目标.这是您所追求的吗? (图下面的示例代码).

未显示的子图

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()

本文地址:https://www.itbaoku.cn/post/2091141.html

问题描述

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?

推荐答案

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.

其他推荐答案

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:

enter image description here

其他推荐答案

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).

subplots without axes shown

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()