为Jupyter内联图修改了matplotlibrc rcParams [英] matplotlibrc rcParams modified for Jupyter inline plots

查看:125
本文介绍了为Jupyter内联图修改了matplotlibrc rcParams的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到过几次这个问题,但是我认为随着jupyter/ipython的更新,此信息也会发生变化.我当前正在运行python 3.5,jupyter(最新)和matplotlib 2.0.
%matplotlib inline图具有自定义属性,这些属性是在导入matplotlibrc文件后设置的.其中最烦人的是figure.facecolor属性设置为透明,这会在复制/粘贴绘图时造成严重破坏,因此我必须在笔记本中重置此属性.我似乎找不到更改此属性的位置,或者是否可以在某个地方创建配置文件来更改这些特殊的inline绘图设置

I have seen this question come up a couple of times, but I think this information changes as jupyter/ipython get updated. I am currently running python 3.5, jupyter (latest) and matplotlib 2.0.
The %matplotlib inline plots have custom properties that are set after the matplotlibrc file is imported. The most annoying of these is that the figure.facecolor property is set to be transparent which wreaks havoc when copy/pasting plots so I have to reset this property in the notebook. I cannot seem to find where this property is changed, or if it is possible to create a configuration profile somewhere to change these special inline plot settings

我的问题是,是否可以更改这些设置,如果可以,我该怎么做?

My question is, is it possible to change these settings, and if so, how would I do that?

推荐答案

一些rcParameter是专门为inline后端设置的.那些是

Some of the rcParameters are set specifically for the inline backend. Those are

{'figure.figsize': (6.0,4.0),  
 'figure.facecolor': (1,1,1,0), # play nicely with white background in the Qt and notebook
 'figure.edgecolor': (1,1,1,0),      
 'font.size': 10, # 12pt labels get cutoff on 6x4 logplots, so use 10pt.
 'figure.dpi': 72, # 72 dpi matches SVG/qtconsole
 'figure.subplot.bottom' : .125 # 10pt still needs a little more room on the xlabel
  }

他们居住的地方是 ipykernel/pylab/config.py 文件. 可以编辑此文件以获得所需的行为,例如通过将面色更改为'figure.facecolor': (1,1,1,1)(无透明度).

And the place where they reside is the ipykernel/pylab/config.py file. This file can be edited to obtain the desired behaviour, e.g. by changing the facecolor to 'figure.facecolor': (1,1,1,1) (no transparency).

另一个选项如下:

rcParameters定义为InlineBackend类的一部分,特别是作为traitlets.Dict对象的InlineBackend.rc属性.

The rcParameters are defined as part of the InlineBackend class, specifically the InlineBackend.rc attribute which is a traitlets.Dict object.

可以使用 ipython配置系统进行以下更改:

Those can be changed using the ipython configuration system as follows.

从命令行键入ipython profile create,它将在~/.ipython中生成默认配置文件.在主配置文件~/.ipython/ipython_config.py中包含以下行:

From the command line type ipython profile create which will generate the default configuration files in ~/.ipython. In the main configuration file ~/.ipython/ipython_config.py include the line:

c.InlineBackend.rc.update({"figure.facecolor": "white"})

这篇关于为Jupyter内联图修改了matplotlibrc rcParams的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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