在 matplotlib 图形上启用白框/禁用透明框 [英] Enable white frames on matplotlib figure/ Disable transparent frames
问题描述
我正在以深色主题运行 ipython notebook.当我在其上构建图表时,图表是白色的,但框架是透明的(因此是黑色的),隐藏了同样黑色的刻度线.有没有办法让框架不透明/白色?
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.
我该如何解决这个问题?谢谢!
How do I solve this? Thanks!
这不是关于改变轴、刻度/标签的颜色,我想添加一个白色背景框架,而不是改变刻度的颜色 - 如果我只是改变颜色打勾,因为数字是白色的
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.
如果要用于每个笔记本,也可以将其添加到ipython 配置文件
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屋!