Python Matplotlib figure title overlaps axes label when using twiny

前端 未结 6 1981
滥情空心
滥情空心 2020-11-27 11:42

I am trying to plot two separate quantities on the same graph using twiny as follows:

fig = figure()
ax = fig.add_subplot(111)
ax.plot(T, r, \'b-\', T, R, \'         


        
6条回答
  •  日久生厌
    2020-11-27 11:53

    Forget using plt.title and place the text directly with plt.text. An over-exaggerated example is given below:

    import pylab as plt
    
    fig = plt.figure(figsize=(5,10))
    
    figure_title = "Normal title"
    ax1  = plt.subplot(1,2,1)
    
    plt.title(figure_title, fontsize = 20)
    plt.plot([1,2,3],[1,4,9])
    
    figure_title = "Raised title"
    ax2  = plt.subplot(1,2,2)
    
    plt.text(0.5, 1.08, figure_title,
             horizontalalignment='center',
             fontsize=20,
             transform = ax2.transAxes)
    plt.plot([1,2,3],[1,4,9])
    
    plt.show()
    

    enter image description here

提交回复
热议问题