python畫對數與半對數座標

import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as sts

if __name__ == '__main__':
    a = 0.031 / 10000 + 0.0337 / 10000
    print(0.0336 * 100 / np.sqrt(a))  # 1320.95

    r = sts.lognorm.rvs(0.954, size=1000)
    c = plt.hist(r, bins=500)
    plt.show()

    # 雙對數座標下
    fig, ax = plt.subplots()
    ax.set_xscale("log")
    ax.set_yscale("log")
    ax.set_adjustable("datalim")
    ax.plot(c[1][:-1], c[0], 'o')
    ax.set_xlim(1e-1, 1e6)
    ax.set_ylim(1e-2, 1e6)
    ax.grid()
    plt.draw()
    plt.show()

    # 半對數座標
    fig1, ax1 = plt.subplots()
    ax1.hist(r, bins=500)
    ax1.set_xscale("log")
    ax1.set_xlim(1e-1, 1e6)
    ax1.grid()
    plt.draw()
    plt.show()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章