无边界 matplotlib 绘图 [英] Borderless matplotlib plots

查看:55
本文介绍了无边界 matplotlib 绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以保存matplotlib图,使图框周围没有边框,同时又保持背景不透明?

Is there a way to save matplotlib graphs without the border around the frame while keeping the background not transparent?

如我在下面的代码中所示将框架设置为"off"不起作用,因为这会删除背景并使之透明,而我想保留白色背景,只是没有边框.

Setting the frame to 'off' as I show in the code below does not work as this removes the background making it transparent whereas I want to retain the white background, just without the borders.

a = fig.gca()  
a.set_frame_on(False)  

这是我正在尝试执行的操作的屏幕截图.如果可以删除边框,那么我可以分别绘制x轴线.

Here is a screenshot of what I'm trying to do. If the border can be removed then I can draw the x-axis line separately.

非常感谢所有建议.

推荐答案

这里有人问过类似的问题:如何去掉顶部和matplotlib中的右轴?.谷歌搜索隐藏轴 matplotlib"给出了第五个链接.

A similar question was asked here: How can I remove the top and right axis in matplotlib?. A Google search for "hide axes matplotlib" gives that as the 5th link.

去除刺:

x = linspace(0, 2 * pi, 1000)
y = sin(x)
fig, ax = subplots()
ax.plot(x, y)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.grid(axis='y')

这篇关于无边界 matplotlib 绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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