How to change defaults in matplot lib and find specific list of rc parameters

我怕爱的太早我们不能终老 提交于 2019-12-31 05:34:12

问题


I am learning matplotlib at the moment and working on changing the rcParams. The documentation on the website appears to be very sparse.

When I look here, there is only a select few examples of rc parameters that can be changed, mainly fonts or line colors, such as:

rcParams['lines.linewidth'] = 2
rcParams['lines.color'] = 'r'

And so forth. I am looking for ways to alter the grid and default figure size for example, but they are not listed here and are only scattered here and there across the web. I want to find a reference list of all the changeable parameters and their descriptions. Does such a reference exist?

Thanks.


回答1:


There is a complete tutorial about rc params: Customizing Matplotlib with style sheets and rcParams.

Further down that tutorial there is a section A sample matplotlibrc file, which contains all valid rc params.

Another option is to just print all rc params out,

print(plt.rcParams)

Concerning the actual question:

  • The grid can be turned on via

    plt.rcParams["axes.grid"] = True
    
  • The figure size can be set via

    plt.rcParams["figure.figsize"] = (8,6)
    



回答2:


From the documentation, you can find the location of the matplotlibrc on your machine as follows:

import matplotlib
matplotlib.matplotlib_fname()

In your text editor, you can uncomment the preset commands. This file is read whenever matplotlib is imported.



来源:https://stackoverflow.com/questions/53399602/how-to-change-defaults-in-matplot-lib-and-find-specific-list-of-rc-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!