在python的plt画图中如何在标签上加入公示

73 阅读1分钟

因为有一个需求,在坐标轴上加上 10^3 这样的公式,好好找一下方案,记录起来。

import matplotlib.pyplot as plt

if __name__=="__main__":
    x = [1, 2, 3, 4, 5]
    y = [10 ** 3, 2 * 10 ** 3, 3 * 10 ** 3, 4 * 10 ** 3, 5 * 10 ** 3]
    plt.plot(x, y)
    plt.ylabel('# of Continuous Links ($10^3$)', fontdict={'family': 'Times New Roman'}, labelpad=3)
    plt.show()

画图的效果:

image.png