Figure title with several colors in matplotlib

后端 未结 2 771
终归单人心
终归单人心 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:44

    The following snippet seems to work.

    import numpy as np
    import matplotlib.pyplot as plt
    
    x = np.arange(0, 5, 0.1);
    y = np.sin(x)
    fig1 = plt.figure(1)
    fig1.text(0.45, 0.95, "Case A", ha="center", va="bottom", size="medium",color="red")
    fig1.text(0.5, 0.95, "&", ha="center", va="bottom", size="medium")
    fig1.text(0.55,0.95,"Case B", ha="center", va="bottom", size="medium",color="blue")
    plt.plot(x, y)
    plt.show()
    

    As far as I can see the title generated by matplotlib title function only contains one text object and hence can only have one font color. This is the reason for making multiple text elements on the figure.

提交回复
热议问题