python

python示例1
# -*- coding:utf-8 -*-  
import math
import matplotlib.pyplot as plt

if __name__ == '__main__':
    x = [float(i) / 100.0 for i in range(1, 300)]
    y = [math.log(i) for i in x]
    plt.plot(x, y, 'r-', linewidth=3, label='log Curve')
    a = [x[20], x[175]]
    b = [y[20], y[175]]
    plt.plot(a, b, 'g-', linewidth=2)
    plt.plot(a, b, 'b*', markersize=15, alpha=0.75)
    plt.legend(loc='upper left')
    plt.grid(True)  # 显示网格  
    plt.xlabel('x')
    plt.ylabel('log(x)')
    plt.show()

python示例2
import numpy as np
import matplotlib.pyplot as plt

if __name__ == '__main__':
    u = np.random.uniform(0.0, 1.0, 10000)  # 产生10000个[0,1)的数  
    plt.hist(u, 80, facecolor='g', alpha=0.2)  # 对应x轴,指定bin(箱子)的个数,80条状图,颜色  
    plt.grid(True)
    plt.show()

    times = 10000
    for time in range(times):
        u += np.random.uniform(0.0, 1.0, 10000)
    print(len(u))
    u /= times
    print(len(u))
    plt.hist(u, 80, facecolor='g', alpha=0.75)
    plt.grid(True)
    plt.show()

# 对数函数的速度  
import math
import matplotlib.pyplot as plt
import numpy as np

if __name__ == '__main__':
    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='r', label='log1.5(x)')
    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='g', label='log2(x)')
    y3 = [math.log(a, 3) for a in x]
    plt.plot(x, y3, linewidth=2, color='b', label='log3(x)')
    plt.legend(loc='lower right')
    plt.grid(True)
    plt.show()

import matplotlib.pyplot as plt

def first_digital(x):
    while x >= 10:
        x /= 10
    return x

if __name__ == '__main__':
    n = 1
    frequency = [0] * 9
    for i in range(1,100):
        n *= i
        m = int(first_digital(n) - 1)
        frequency[m] += 1
    print(frequency)

    plt.plot(frequency,'r-',linewidth=2)
    plt.plot(frequency,'go',markersize=8)
    plt.grid(True)
    plt.show()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值