use*_*702 2 python label position matplotlib

从图中可以看出,xlabel和ylabe超出了绘图区域,无法完全显示。
有人可能会说改变字体大小,但我希望字体变大。
下面是代码:
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)
Run Code Online (Sandbox Code Playgroud)
现在可能有点晚了,但无论如何:
如果图中有任何子图,则应指定图的内边距和子图内的空间。以下代码将对您有所帮助。在展示情节之前把它放在右边。
plt.subplots_adjust(wspace=0.6, hspace=0.6, left=0.1, bottom=0.22, right=0.96, top=0.96)
Run Code Online (Sandbox Code Playgroud)
但是,另一个问题是如何在 subplot_adjust 中指定上述参数的值,那么答案是使用 subplot_tool 。在显示绘图之前放置以下代码,然后会出现一个弹出窗口,您可以使用这些值并找到您喜欢的值。
plt.subplot_tool()
Run Code Online (Sandbox Code Playgroud)
另外,最好使用 Figsize 参数指定图形的总大小。
我希望它有帮助。
| 归档时间: |
|
| 查看次数: |
4211 次 |
| 最近记录: |