matplotlib configuration for inline backend in jupyter notebook

后端 未结 5 1494
醉酒成梦
醉酒成梦 2020-12-14 09:14

I\'d like to learn how to configure the defaults for matplotlib using the inline backend in jupyter notebook. Specifically, I\'d like to set default \'figure.figsize’ to [7.

相关标签:
5条回答
  • 2020-12-14 09:38

    Using Jupyter on windows at least, I was able to do it using something very much like venkat's answer, i.e.:

    %matplotlib inline
    import matplotlib
    matplotlib.rcParams['figure.figsize'] = (8, 8)
    

    I did this to square the circle, which had been rather eliptical up to that point. See, squaring the circle is not that hard. :)

    0 讨论(0)
  • 2020-12-14 09:39

    Use figsize(width,height) in the top cell and it changes width of following plots

    0 讨论(0)
  • 2020-12-14 09:41

    Note that the path of ipython_kernel_config.py differs if you run ipython from a virtual environment. In that case, dig in the path where the environment is stored.

    0 讨论(0)
  • 2020-12-14 09:45

    The Jupyter/IPython split is confusing. Jupyter is the front end to kernels, of which IPython is the defacto Python kernel. You are trying to change something related to matplotlib and this only makes sense within the scope of the IPython kernel. Making a change to matplotlib in ~/.jupyter/jupyter_notebook_config.py would apply to all kernels which may not make sense (in the case of running a Ruby/R/Bash/etc. kernel which doesn't use matplotlib). Therefore, your c.InlineBackend.rc setting needs to go in the settings for the IPython kernel.

    Edit the file ~/.ipython/profile_default/ipython_kernel_config.py and add to the bottom: c.InlineBackend.rc = { }.

    Since c.InlineBackend.rc specifies matplotlib config overrides, the blank dict tells the IPython kernel not to override any of your .matplotlibrc settings.

    If the file doesn't exist, run ipython profile create to create it.

    0 讨论(0)
  • 2020-12-14 09:47

    For jupyter 5.x and above with IPython kernels, you can just override particular keys and leave the rest by putting things like this, with your desired figsize in your ~/.ipython/profile_default/ipython_kernel_config.py:

    c = get_config()
    c.InlineBackend.rc.update({"figure.figsize": (12, 10)})
    
    0 讨论(0)
提交回复
热议问题