你可以使用 matplotlib.pyplot.text。
如果您指定transform=ax.transAxes,使坐标相对于坐标轴边界框,并且verticalalignment='top',您可以获得与您发布的图片非常相似的东西。
import numpy as np
import matplotlib.pyplot as plt
x_val = np.random.uniform(low=-4, high=4, size=200)
fig, ax = plt.subplots()
ax.hist(x_val,bins=20)
textbox = '\n'.join([
'Evaluation flow name: ',
'Evaluation description: ',
'',
'Evaluation flow SVN Revision: ',
'Dataset path: ',
'Dataset name: ',
'',
'Filter: ',
'Grouping: ',
'Files selected with filter and grouping: ',
'Files with all needed signals: ',
'',
'...',
'...',
'...',
])
bbox = dict(boxstyle='square', facecolor='lavender', alpha=0.5)
fig.text(1.1,1,textbox,fontsize=10,transform=ax.transAxes, bbox=bbox,
verticalalignment='top')
给出以下输出:
https://i.stack.imgur.com/57rnI.png
对于文本,我使用 join() 只是为了更容易阅读和修改(对于一个充满 '\n' 的长字符串,也许有更好的方法来做到这一点。