使用matplotlib畫出log的圖像


以下內容是學習筆記,若有侵權,立即刪除!

import math
import matplotlib.pyplot as plt
import numpy as np
if __name__ == '__main__':
    #獲得浮點類型numpy數組
    x = np.arange(0.05,3,0.05)
    #獲得函數結果
    y1 = [math.log(a,1.5) for a in x]
    #畫圖
    plt.plot(x, y1, linewidth=2, color='#007500', label='log1.5(x)')
    #在坐標1處描紅
    plt.plot([1,1],[y1[0], y1[1]],"r--",linewidth=2)

    y2 = [math.log(a,2) for a in x]
    plt.plot(x,y2, linewidth=2,color='#9F35FF', label='log2(x)')

    y3 = [math.log(a,3) for a in x]
    plt.plot(x, y3, linewidth=2, color='#f75000', label='log3(x)')

    plt.legend(loc='lower right')#在右下角顯示計算用的函數
    plt.grid(True)#在坐標系上畫格子
    #打印圖片
    plt.show()

 

效果圖:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM