要使用逗號作為千位分隔符格式化 y 軸,我在 StackOverflow 上找到了這個不錯的解決方案。
fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.get_yaxis().set_major_formatter(
matplotlib.ticker.FuncFormatter(lambda x, p: format(int(x), ',')))
如果我想用空格作為分隔符,我該怎么辦?如果我嘗試,Ticker 不喜歡:
matplotlib.ticker.FuncFormatter(lambda x, p: format(str(x), ' ')))
uj5u.com熱心網友回復:
干得好
fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.get_yaxis().set_major_formatter(matplotlib.ticker.FuncFormatter(lambda x, p: '{:,}'.format(int(x)).replace(",", " ")))
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/317826.html
標籤:Python matplotlib
上一篇:置信區間3維圖
