【发布时间】:2022-01-22 02:12:05
【问题描述】:
【问题讨论】:
标签: matplotlib
【问题讨论】:
标签: matplotlib
您可以设置格式化程序以显示绝对值:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(100)
y1 = np.random.normal(0.1, 1, 100).cumsum()
y1 -= y1.min()
y2 = np.random.normal(0.1, 1, 100).cumsum()
y2 -= y2.min()
fig, ax = plt.subplots()
ax.bar(x, y1)
ax.bar(x, -y2)
ax.yaxis.set_major_formatter(lambda x, pos: f'{abs(x):g}')
ax.margins(x=0)
plt.show()
【讨论】: