使用matplotlib画出log的图像

2019/04/11 08:54
阅读数 107

以下内容是学习笔记,若有侵权,立即删除!

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()

 

效果图:

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部