我需要用几条不同长度的数据线来注释一个 pylab 矩形。通过 matplotlib 文档和谷歌搜索,我找不到给注释的不同部分不同大小的方法。
以下代码段演示了该问题:
import pylab
from matplotlib.patches import Rectangle
pylab.rcParams['verbose.level'] = 'debug-annoying'
def draw_rectangle(lower, upper, entry):
ax = pylab.subplot(111)
r = Rectangle( lower, upper[0]-lower[0], upper[1] - lower[1],
edgecolor='k')
ax.add_patch(r)
textRank = str(entry['rank'])
textTeamName = entry['teamName']
textSubmissionDate = entry['submissionDate']
text = textRank + "\n" + textTeamName + "\n" + textSubmissionDate
ax.add_artist(r)
rx, ry = r.get_xy()
cx = rx + r.get_width()/2.0
cy = ry + r.get_height()/2.0
ax.annotate(text, (cx, cy), color='w', weight='bold', ha='center', va='center', size=14)
if __name__ == '__main__':
entry = {'rank': 22, 'submissionDate': '12/21/2012 4:58:45 AM', 'teamName': 'A very very very very very very very very very very long name'}
lower = [0,0]
upper = [1,1]
draw_rectangle(lower, upper, entry)
pylab.show()
例如,有没有办法让“teamName”的字体大小与“rank”的字体大小不同的注释?
另一个问题是我找不到字体大小与缩放相关的方法:
我正在创建一个树形图,即 pylab 窗口填充了不同大小的矩形。如果我想为不同的矩形创建注释,长数据需要非常小(保持在各自矩形的边界内)。但是,我希望长数据线的字体大小随着放大而增大。