我在 matplotlib 的 x 軸上繪制日期和時間。因為我想繪制盡可能多的標簽,所以我在 x 標簽中使用換行符,如下所示:

不幸的是,當我將滑鼠懸停在圖表上時,這具有調整 matplotlib 視窗大小的副作用,因為它試圖在底部列印包含換行符的 x 值。在此處查看此視頻作為演示:

uj5u.com熱心網友回復:
我不想擺脫工具列,但我只需要它不列印右下角的 x 點(這是導致視窗調整大小的原因)。
您可以使用monkeypatchax.format_coord為給定的 x、y 值(或如下所示的 None)顯示不同格式的字串。
fig, ax = plt.subplots()
ax.format_coord = lambda x, y : '' # don't display anything
plt.show()
如果要修改原始的字串ax.format_coord,則必須包裝原始函式:
fig, ax = plt.subplots()
old_function = ax.format_coord
ax.format_coord = lambda x, y: old_function(x, y) "some random nonsense"
plt.show()
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/512121.html
標籤:Pythonpython-3.x约会时间matplotlibUnix时间戳
上一篇:如何使用pandas計算和累積每個行名的值而不丟失Python中的DateTime順序
下一篇:需要幫助從本網站抓取表格資料
