本文介绍了Matplotlib suptitle 打印在旧标题上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 suptitle 打印标题,并且我想偶尔替换此标题.目前我正在使用:

I am trying to use suptitle to print a title, and I want to occationally replace this title. Currently I am using:

self.ui.canvas1.figure.suptitle(title)

其中 figure 是一个 matplotlib 图形(canvas1 是一个 mplCanvas,但这并不相关),而 title 是一个 python 字符串.

where figure is a matplotlib figure (canvas1 is an mplCanvas, but that is not relevant) and title is a python string.

目前,这是可行的,除了当我稍后再次运行此代码时,它只是在旧文本的顶部打印新文本,从而导致标题难以阅读.

Currently, this works, except for the fact that when I run this code again later, it just prints the new text on top of the old, resulting in a gargeled, unreadable title.

如何替换图形的旧 suptitle,而不是仅仅打印出来?

How do you replace the old suptitle of a figure, instead of just printing over?

谢谢,

泰勒

推荐答案

figure.suptitle 返回 matplotlib.text.Text 实例.您可以保存并设置新标题:

figure.suptitle returns a matplotlib.text.Text instance. You can save it and set the new title:

txt = fig.suptitle('A test title')
txt.set_text('A better title')
plt.draw() 

这篇关于Matplotlib suptitle 打印在旧标题上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 03:26