自定义Rc

我不是想在这里做一个好看的人物,而只是为了展示一些动态定制rc params的例子

如果您希望以交互方式工作,并且需要为图形创建不同的默认设置(例如,一组用于发布的默认设置,一组用于交互式探索),您可能希望在自定义模块中定义一些设置默认值的函数, 例如,:

  1. def set_pub():
  2. rc('font', weight='bold') # bold fonts are easier to see
  3. rc('tick', labelsize=15) # tick labels bigger
  4. rc('lines', lw=1, color='k') # thicker black lines
  5. rc('grid', c='0.5', ls='-', lw=0.5) # solid gray grid lines
  6. rc('savefig', dpi=300) # higher res outputs

然后,当您以交互方式工作时,您只需要:

  1. >>> set_pub()
  2. >>> subplot(111)
  3. >>> plot([1,2,3])
  4. >>> savefig('myfig')
  5. >>> rcdefaults() # restore the defaults

自定义Rc示例

  1. import matplotlib.pyplot as plt
  2. plt.subplot(311)
  3. plt.plot([1, 2, 3])
  4. # the axes attributes need to be set before the call to subplot
  5. plt.rc('font', weight='bold')
  6. plt.rc('xtick.major', size=5, pad=7)
  7. plt.rc('xtick', labelsize=15)
  8. # using aliases for color, linestyle and linewidth; gray, solid, thick
  9. plt.rc('grid', c='0.5', ls='-', lw=5)
  10. plt.rc('lines', lw=2, color='g')
  11. plt.subplot(312)
  12. plt.plot([1, 2, 3])
  13. plt.grid(True)
  14. plt.rcdefaults()
  15. plt.subplot(313)
  16. plt.plot([1, 2, 3])
  17. plt.grid(True)
  18. plt.show()

下载这个示例