使用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