Figure title with several colors in matplotlib

后端 未结 2 769
终归单人心
终归单人心 2021-01-04 01:18

Is it possible to have multiple font colors in matplotlib figure titles? Something like this \"three

2条回答
  •  囚心锁ツ
    2021-01-04 01:48

    One can also use figtext() command of matplotlib, like below,

    import numpy as np
    import matplotlib.pyplot as plt
    
    x = np.arange(0, 5, 0.1)
    for i in range(4):
        plt.subplot(2,2,i+1)
        plt.plot(x, np.sin((i+1)*x),'r')
        plt.plot(x, np.cos(4*x/(i+1)),'b')
        plt.title('(i+1)='+str(i+1))
    
    plt.figtext(0.47, 0.96, "Case A", fontsize='large', color='r', ha ='right')
    plt.figtext(0.53, 0.96, "Case B", fontsize='large', color='b', ha ='left')
    plt.figtext(0.50, 0.96, ' vs ', fontsize='large', color='k', ha ='center')
    plt.show()
    

提交回复
热议问题