我正试图在Python中向Matplotlib中的图表添加文本。它没有显示-没有任何错误。
fig = plt.figure(figsize=(12, 8))
ax = fig.add_subplot()
dtFmt = mdates.DateFormatter('%d.%m - %H:%M')
plt.gca().xaxis.set_major_formatter(dtFmt)
plt.grid()
ax.set_ylim(bottom=0, top=df.threadswaiting.max()+10)
ax.plot(df.threadsrunning, label='Running Threads', color='blue')
ax.plot(df.threadswaiting, label='Waiting Threads', color='red')
ax.set_title(f'Thread load\nLast {offset}\ncreated: {timestamp}')
ax.set_ylabel('Threads')
ax.set_xlabel('Time')
# Definition of teststring, which is not showing up:
ax.text(1, 1, 'Teststring')
plt.legend()
plt.show()
有人帮忙吗?谢谢!
Dataframe “df”由以下形式的数据组成:
timestamp,memtotal,memfree,memused,mempercentage,threadsmax,threadsrunning,threadswaiting
2023-02-06T10:34:03.691266, 17179.869184, 13149.334632, 3950.842776, 23.0, 5, 7, 38
2023-02-06T10:34:34.450291, 17179.869184, 15950.03556, 2583.789464, 15.04, 5, 4, 0
2023-02-06T10:35:04.722786, 17179.869184, 13645.117544, 3530.557336, 20.55, 5, 9, 43
2023-02-06T10:35:35.068253, 17179.869184, 12564.56868, 4615.300504, 26.86, 5, 3, 0
2023-02-06T10:36:05.355758, 17179.869184, 12443.191912, 4732.482968, 27.55, 5, 6, 41
2023-02-06T10:36:35.638119, 17179.869184, 14418.945808, 2664.454384, 15.51, 5, 5, 38
2023-02-06T10:37:05.915987, 17179.869184, 10899.06084, 6217.893784, 36.19, 5, 5, 64
2023-02-06T10:37:36.195419, 17179.869184, 14730.19836, 2252.538536, 13.11, 5, 5, 63
2023-02-06T10:38:06.476530, 17179.869184, 13079.04248, 3819.808336, 22.23, 5, 8, 65
2023-02-06T10:38:36.753379, 17179.869184, 13479.695576, 3700.173608, 21.54, 5, 3, 0
2023-02-06T10:39:07.034731, 17179.869184, 12682.653384, 4484.632888, 26.1, 5, 8, 35
2023-02-06T10:39:37.326827, 17179.869184, 14345.964728, 2829.710152, 16.47, 5, 2, 0
2023-02-06T10:40:07.617135, 17179.869184, 11636.444344, 5535.036232, 32.22, 5, 6, 47
2023-02-06T10:40:37.912047, 17179.869184, 14231.936984, 2947.9322, 17.16, 5, 3, 0
2023-02-06T10:41:08.192663, 17179.869184, 9836.306392, 7339.368488, 42.72, 5, 4, 0
2023-02-06T10:41:38.470597, 17179.869184, 13915.799128, 3264.070056, 19.0, 5, 2, 0
1条答案
按热度按时间vmdwslir1#
现在起作用了。但我还是不明白为什么。