在matplotlib图形上启用白色框架/禁用透明框架 [英] Enable white frames on matplotlib figure/ Disable transparent frames

查看:121
本文介绍了在matplotlib图形上启用白色框架/禁用透明框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以深色主题运行ipython笔记本.当我以此为基础构建图表时,图表是白色的,但是框架是透明的(因此很暗),隐藏了也很暗的刻度线.有没有办法使框架不透明/白色?

I'm running ipython notebook on a dark theme. When I build a chart on this, the chart is white, but the frame is transparent (hence dark), hiding the ticks which are also dark. Is there a way to make the frame not transparent/ white?

由于黑色背景,几乎没有刻度线.

The ticks are barely visible due to black background.

我该如何解决?谢谢!

这与更改轴,刻度线/标签的颜色无关,我正在考虑添加白色背景框架,而不更改刻度线的颜色-如果我仅更改刻度线的颜色将很丑陋.滴答作响,因为数字是白色

This is not about changing the colors of axis, ticks/labels, I'm thinking of adding a white background frame, not changing the colors of ticks - it'll be ugly if I just change the color of the ticks because the figure is white

推荐答案

在jupyter中显示的带有%matplotlib inline后端的图(通常是默认值)是通过将其通过savefig保存到png中而创建的显示. savefig具有参数facecolor,该参数设置图形背景的颜色.可以将其设置为白色,例如fig.savefig("name.png", facecolor="w").

The figure shown in jupyter with the %matplotlib inline backend (which is often the default) is created via saving it through savefig to a png that is then displayed. savefig has an argument facecolor which sets the color of the figure background. This can be set to white, e.g. fig.savefig("name.png", facecolor="w").

保存选项可以在jupyter配置中进行调整.要获得白色背景,可以设置

The options for saving can be adapted in the jupyter configuration. To achieve a white background one can set

%config InlineBackend.print_figure_kwargs={'facecolor' : "w"}

在显示图之前在单元格中按

.

in a cell prior to showing the plot.

如果要用于每个笔记本,也可以将其添加到

If that is to be used for every notebook, it can also be added to the ipython configuration file

c = get_config()
c.InlineBackend.print_figure_kwargs={'facecolor' : "w"}

这篇关于在matplotlib图形上启用白色框架/禁用透明框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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