2

enter image description here

As can be seen in the figure, the xlabel and ylabe is out of plot region and can not show fully.

Someone may say change the fontsize, but I want the fontsize to be large.

below is the code:

from numpy import *
from pylab import *
tduration=3600

if tduration<960:
    time=linspace(0,tduration,120)
else:
    n=(tduration-960)/480
    time1=linspace(0,960,8,endpoint=False)
    time2=linspace(960,tduration,n)

    time=hstack((time1,time2))
timemin=time/60
T0=20
Tf=T0+345*log10(8*timemin+1)
timetem=column_stack((timemin,Tf))
savetxt("timetem.txt",timetem,newline='\r\n',fmt='%f')
heatingRate=345/(8*timemin+1)
fig,ax1 =subplots()

ax2 = ax1.twinx()


rc('font',family='Times New Roman')


ax1.plot(timemin,Tf,'k',linewidth=3,label='ISO834 fire curve')
ax2.plot(timemin,heatingRate,'b--',linewidth=3,label='heating rate')
ax1.plot(0, 0,'b--', label = 'heating rate',linewidth=3)
leg=ax1.legend(loc='best',fontsize=24)
leg.get_frame().set_alpha(0.0)

ax1.set_ylabel(r"T$(^{\circ}C)$",fontsize=24,fontname="Times New Roman")
ax2.set_ylabel(r"Heating rate($^{\circ}C$/min)",fontsize=24,fontname="Times     New Roman")
ax1.set_xlabel("Time(min)",fontsize=24,fontname="Times New Roman") 
ax1.tick_params(labelsize=24)
ax2.tick_params(labelsize=24)
ax1.grid()
show()
fig.savefig('iso834 with hr.png', transparent=True)
user3737702
  • 591
  • 1
  • 10
  • 17
  • In my experience, *the probability of eliciting SO answer is inversely proportional to verbosity of the code*. Could you reproduce similar error with a minimal code example? Seems better now. – Zero Apr 21 '15 at 08:58
  • 3
    Did you already try `fig.tight_layout()` just before `show()`? ... usually the issue with `xlabel` and `ylabel` is solved with that – plonser Apr 21 '15 at 09:06
  • Wow! It works perfectly~ one more lesson~ thanks~ – user3737702 Apr 21 '15 at 09:09
  • possible duplicate of [Why is my xlabel cut off in my matplotlib plot?](http://stackoverflow.com/questions/6774086/why-is-my-xlabel-cut-off-in-my-matplotlib-plot) – plonser Apr 21 '15 at 09:22
  • Oops...true... but mine has figure which makes problem easy to see... – user3737702 Apr 24 '15 at 14:39

1 Answers1

5

It might be a bit late right now, but anyway:

You should specify the inner margins for your figure and the spaces within subplots, if you have any subplots in your figure. Following code will help you. Put it right before showing the plot.

plt.subplots_adjust(wspace=0.6, hspace=0.6, left=0.1, bottom=0.22, right=0.96, top=0.96)

But, another question would be how to specify the values for above parameters in subplot_adjust, then the answer is to use subplot_tool. Put following code right before showing the plot and a popup window comes up and you can play with the values and find the one you like.

plt.subplot_tool()

Also, it is better to specify the total size of your figure using the figsize argument.

I hope it helps.

mgNobody
  • 738
  • 7
  • 23