【问题标题】:Jupyter notebook: How to set matplotlib figure default size persistently, even after `from matplotlib import pyplot`?Jupyter notebook:如何持续设置matplotlib图形默认大小,即使在`from matplotlib import pyplot`之后?
【发布时间】:2019-07-26 18:25:20
【问题描述】:

我正在寻找一种方法来配置我的默认笔记本设置并设置绘图和图形的大小,这样我就不必为每个笔记本单独手动设置。

我知道像How to set the matplotlib figure default size in ipython notebook? 这样的问题详细说明了如何使用jupyter_notebook_config.py

但这不起作用,大概是因为我在笔记本中重新导入了 pyplot。有没有更好的方法来设置默认设置、行为、选项等?

【问题讨论】:

  • 在导入 pyplot 后使用plt.rc('figure', figsize=(20.0, 10.0))(如建议的那样)怎么样?
  • @JoshFriedlander 将plt.rc('figure', figsize=(20.0, 10.0)) 添加到~/.ipython/profile_default/startup/startup.ipy 无效。
  • 我认为如果你在其他地方使用 matplotlib 并且你想在那里进行其他设置,这可能会很困难。它应该如何知道您是在 IPython 之外还是在其他环境中使用它?但是,如果你只将它用于IPython,你知道this,它指的是here吗?
  • 我希望在启动笔记本服务器时设置一些参数。 似乎jupyter_notebook_config.py 的用途,但在那里添加命令并没有成功。

标签: python matplotlib jupyter-notebook


【解决方案1】:

在 python 3.x 中

ipython profile create
ipython profile locate

找到并编辑 ipython_kernel_config.py 手动添加行:

c.InlineBackend.rc = {'figure.dpi':160}

rcParams 参考

https://matplotlib.org/3.1.1/tutorials/introductory/customizing.html

【讨论】:

    【解决方案2】:

    在 matplotlib 中设置默认绘图大小的一个方法是:

    from pylab import rcParams
    rcParams['figure.figsize'] = 8, 6
    

    其中 8、6 是您要设置的图形大小。

    【讨论】:

    • 我正在寻找一种方法将其设置为所有笔记本的默认设置,这样我就不必手动将其添加到每个笔记本中。
    猜你喜欢
    • 2013-06-18
    • 2017-04-06
    • 2018-04-25
    • 1970-01-01
    • 2017-09-18
    • 2021-04-20
    • 2018-08-12
    • 1970-01-01
    • 2018-09-06
    相关资源
    最近更新 更多