0

I'm trying to figure out how to fix the position of text in multiple subplots, where the x,y axes are changing. Below is a copy of my code. I've tried transforming the axes, but the code disappears altogether. I can't specify the values for x,y axes, because for some it becomes impossible to see the data.

 fig, axs = plt.subplots(2, 3, figsize=(30,11))
    #fig.suptitle('Basin ' + basin_number)
    fig.suptitle('OFFSET = 5  ' + files[f][21:-7], fontsize=20 )
    basin_name = files [f][21:-7]
    #lim = min(axs[0,0])
    #ylim = get(gca,'ylim')
    #linear reg, Qb-Qt vs Qb-Qf
    axs[0, 0].plot(XX,predict_mean_ci_low,'-',color='C0', label="95% Conf. Band for Slope")
    axs[0, 0].plot(XX,predict_mean_ci_upp,'-',color='C0')
    axs[0, 0].plot(XX,predict_ci_upp,'--',color='C8', label="95% Prediction Bands for response")
    axs[0, 0].plot(XX,predict_ci_low,'--',color='C8')
    axs[0, 0].plot(XX,YY,'.',color='C7')
    axs[0, 0].plot(XX,fittedvalues,color='C1')
    axs[0, 0].set_title('Linear Regression')
    axs[0, 0].set_xlabel(r'$Q_b-Q_t$')
    axs[0, 0].set_ylabel(r'$Q_b-Q_f$') 
    axs[0,0].legend(loc="upper left")
    axs[0,0].text(1,-1, 'slope = {:.2f}\nr² = {:.2f}'.format(float(spp),float(r22)), bbox=dict(facecolor='white', alpha=0.5))
    #axs[0,0].format(xlabel=r'$(Q_b-Q_t)/(\mathrm{max}|Q_b-Q_f|)$')
    #transform=plt.gca().transAxes
    # Qb vs time
    axs[0, 1].plot(db.index,db.Qb, 'tab:orange')
    axs[0, 1].set_title('$Q_b$ vs time')
    axs[0, 1].set_xlabel('time')
    axs[0, 1].set_ylabel(r'$Q_b$')
    
    #Qt vs time 
    axs[1, 0].plot(db.index, db.Qt, 'tab:green')
    axs[1, 0].set_title(r'$Q_t$ vs time')
    axs[1, 0].set_xlabel('time')
    axs[1, 0].set_ylabel(r'$Q_t$')
    
    # Qf vs time 
    axs[1, 1].plot(db.index, db.Qf, 'tab:red')
    axs[1, 1].set_title(r'$Q_f$ vs time')
    axs[1, 1].set_xlabel('T=time')
    axs[1, 1].set_ylabel(r'$Q_f$')
    
    # dL/dt vs time 
    axs[0,2].plot(db.index, db.dLdt, 'tab:blue')
    axs[0,2].set_title(r'$dL/dt$ vs time')
    axs[0,2].set_xlabel('time')
    axs[0,2].set_ylabel(r'$dL/dt$')
    
    # Area vs time 
    axs[1,2].plot(db.index, db.A, 'tab:purple')
    axs[1,2].set_title('Area vs time')
    axs[1,2].set_xlabel('time')
    axs[1,2].set_ylabel('Area')
    
    plt.savefig('glacier_all_annual/OFFSET_5_basin_' + basin_name + '.png', format='png', dpi=150)
    plt.show()  
    
    plt.close()    

enter image description here

enter image description here

I've tried transforming axes, the text dissapears. I've tried setting parameters for x,y axes, but for some of our data it becomes too difficult to see.

AlexK
  • 2,855
  • 9
  • 16
  • 27
  • What specifically do you mean by "fixing the position"? What is your desired result? Your post would greatly benefit from a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) with a sample data input, so that others could easily reproduce your problem. – AlexK Feb 09 '23 at 23:10
  • Does this answer your question? [Putting text in top left corner of matplotlib plot](https://stackoverflow.com/questions/8482588/putting-text-in-top-left-corner-of-matplotlib-plot) – Jody Klymak Feb 10 '23 at 02:06
  • It's unclear. See [ask]. Why can't you specify the x and y coordinates? You should specify proper values. – relent95 Feb 10 '23 at 03:15

0 Answers0