เปลี่ยนชื่อหน้าต่างรูปใน pylab


93

ฉันจะตั้งชื่อหน้าต่างรูปใน 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

5
plt.suptitle('figure title')และplt.gcf().canvas.set_window_title('window title')และplt.figure('window title')
Trevor Boyd Smith

คำตอบ:


132

หากคุณต้องการเปลี่ยนหน้าต่างจริงๆคุณสามารถทำได้:

fig = pylab.gcf()
fig.canvas.set_window_title('Test')

ไม่ทำงาน. ฉันมีตัวเลขหลายตัวที่จะแสดง นอกจากนี้ฉันนำเข้า pylab ผ่านfrom pylab import *และpylab.title("test")และtitle("test")จะไม่ได้ทำงาน
Omar

ฉันใช้รหัสนี้: matplotlib.org/3.1.0/gallery/user_interfaces/… และสงสัยว่าจะเปลี่ยนชื่อร่าง matplotlib ที่นี่ได้อย่างไร? ความคิดใด ๆ ?
sqp_125

35

จากคำตอบของ Andrew หากคุณใช้ pyplot แทน pylab แล้ว:

fig = pyplot.gcf()
fig.canvas.set_window_title('My title')

27

คุณยังสามารถตั้งชื่อหน้าต่างเมื่อคุณสร้างรูป:

fig = plt.figure("YourWindowName")

จากเอกสาร: If num is a string, the window title will be set to this figure's num. ฉันเห็นคนส่วนใหญ่ส่งต่อตัวเลขดังนั้นการส่งชื่อโดยตรงจะดีกว่ามาก ขอบคุณ!
varagrawal

14

ฉันใช้fig.canvas.set_window_title('The title')กับfigได้รับpyplot.figure()และมันก็ใช้ได้ดีเช่นกัน:

import matplotlib.pyplot as plt
...
fig = plt.figure(0)
fig.canvas.set_window_title('Window 3D')

ป้อนคำอธิบายภาพที่นี่

(ดูเหมือน.gcf()และ.figure()ทำงานคล้ายกันที่นี่)


2
ดูเหมือน.figure()สร้างใหม่figureในขณะที่.gcf()ย่อมาจาก get current figure ซึ่งเป็นสิ่งที่ทำได้จริง
Ibrahim.H
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.