ฉันจะตั้งชื่อหน้าต่างรูปใน pylab / python ได้อย่างไร
fig = figure(9) # 9 is now the title of the window
fig.set_title("Test") #doesn't work
fig.title = "Test" #doesn't work
ฉันจะตั้งชื่อหน้าต่างรูปใน pylab / python ได้อย่างไร
fig = figure(9) # 9 is now the title of the window
fig.set_title("Test") #doesn't work
fig.title = "Test" #doesn't work
คำตอบ:
หากคุณต้องการเปลี่ยนหน้าต่างจริงๆคุณสามารถทำได้:
fig = pylab.gcf()
fig.canvas.set_window_title('Test')
from pylab import *และpylab.title("test")และtitle("test")จะไม่ได้ทำงาน
จากคำตอบของ Andrew หากคุณใช้ pyplot แทน pylab แล้ว:
fig = pyplot.gcf()
fig.canvas.set_window_title('My title')
คุณยังสามารถตั้งชื่อหน้าต่างเมื่อคุณสร้างรูป:
fig = plt.figure("YourWindowName")
If num is a string, the window title will be set to this figure's num. ฉันเห็นคนส่วนใหญ่ส่งต่อตัวเลขดังนั้นการส่งชื่อโดยตรงจะดีกว่ามาก ขอบคุณ!
.figure()สร้างใหม่figureในขณะที่.gcf()ย่อมาจาก get current figure ซึ่งเป็นสิ่งที่ทำได้จริง
plt.suptitle('figure title')และplt.gcf().canvas.set_window_title('window title')และplt.figure('window title')